Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
1c32ec60
Commit
1c32ec60
authored
Jan 21, 2016
by
Nick Stenning
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2883 from hypothesis/remove-blocklist
Remove the static blocklist
parents
d0abd651
8dc8dd2e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
153 deletions
+0
-153
blocklist.js
h/static/scripts/blocklist.js
+0
-94
blocklist-test.js
h/static/scripts/test/blocklist-test.js
+0
-59
No files found.
h/static/scripts/blocklist.js
deleted
100644 → 0
View file @
d0abd651
var
blocklist
=
(
function
()
{
'use strict'
;
/* Parse the given URL and return an object with its different components.
*
* Any or all of the components returned may be undefined.
* For example for the URL "http://twitter.com" port, path query and anchor
* will be undefined.
*
*/
var
parseUrl
=
function
(
url
)
{
// Regular expression from Douglas Crockford's book
// JavaScript: The Good Parts.
var
regex
=
/^
(?:([
A-Za-z
]
+
)
:
)?(\/{0,3})([
0-9.
\-
A-Za-z
]
+
)(?:
:
(\d
+
))?(?:\/([^
?#
]
*
))?(?:\?([^
#
]
*
))?(?:
#
(
.*
))?
$/
;
var
result
=
regex
.
exec
(
url
);
if
(
result
)
{
return
{
scheme
:
result
[
1
],
host
:
result
[
3
],
port
:
result
[
4
],
path
:
result
[
5
],
query
:
result
[
6
],
anchor
:
result
[
7
]
};
}
return
{
scheme
:
undefined
,
host
:
undefined
,
port
:
undefined
,
path
:
undefined
,
query
:
undefined
,
anchor
:
undefined
};
};
/* Return true if the given url is blocked by the given blocklist. */
var
isBlocked
=
function
(
url
,
blocklist
)
{
url
=
url
||
''
;
// Match against the hostname only, so that a pattern like
// "twitter.com" matches pages like "twitter.com/tag/foo".
var
hostname
=
parseUrl
(
url
).
host
;
if
(
hostname
===
undefined
)
{
// This happens with things like chrome-devtools:// URLs where there's
// no host.
return
false
;
}
var
regexSpecialChars
=
'^$.+?=|
\
/()[]{}'
;
// '*' deliberately omitted.
for
(
var
pattern
in
blocklist
)
{
if
(
blocklist
.
hasOwnProperty
(
pattern
))
{
// Escape regular expression special characters.
for
(
var
i
=
0
;
i
<
regexSpecialChars
.
length
;
i
++
)
{
var
c
=
regexSpecialChars
.
charAt
(
i
);
pattern
=
pattern
.
replace
(
c
,
'
\
\'
+ c);
}
// Turn * into .* to enable simple patterns like "*.google.com".
pattern = pattern.replace('
*
', '
.
*
');
// Blocklist patterns should match from the start of the URL.
// This means that "google.com" will _not_ match "mail.google.com",
// for example. (But "*.google.com" will match it.)
pattern = '
^
' + pattern;
if (hostname.match(pattern)) {
return true;
}
}
}
return false;
};
return {
parseUrl: parseUrl,
isBlocked: isBlocked
};
})();
if (typeof(window.h) !== '
undefined
') {
// Looks like blocklist.js is being run by the Chrome extension, so add to
// window.h like the rest of the Chrome extension libs do.
window.h.blocklist = blocklist;
} else if (typeof(module) !== '
undefined
') {
// Looks like blocklist.js being run by the frontend tests, so export the
// blocklist using browserify.
module.exports = blocklist;
} else {
// Looks like blocklist.js is being run by the bookmarklet, so we don'
t
need
// to export anything because it gets inlined into embed.js by Jinja2.
}
h/static/scripts/test/blocklist-test.js
deleted
100644 → 0
View file @
d0abd651
describe
(
'parseUrl'
,
function
()
{
'use strict'
;
var
blocklist
=
require
(
'../blocklist'
);
var
parseUrl
=
blocklist
.
parseUrl
;
it
(
"returns 'http' for the scheme for http:// URLs"
,
function
()
{
assert
.
equal
(
parseUrl
(
"http://example.com"
).
scheme
,
"http"
);
});
it
(
"returns 'https' for the scheme for https:// URLs"
,
function
()
{
assert
.
equal
(
parseUrl
(
"https://example.com"
).
scheme
,
"https"
);
});
it
(
"returns the host part correctly"
,
function
()
{
var
parts
=
parseUrl
(
"https://example.com:23/foo/bar?oh=no#gar"
);
assert
.
equal
(
parts
.
host
,
"example.com"
);
});
it
(
"returns the port part correctly"
,
function
()
{
var
parts
=
parseUrl
(
"https://example.com:23/foo/bar?oh=no#gar"
);
assert
.
equal
(
parts
.
port
,
"23"
);
});
it
(
"returns undefined for the port if there isn't one"
,
function
()
{
var
parts
=
parseUrl
(
"https://example.com/foo/bar?oh=no#gar"
);
assert
.
equal
(
parts
.
port
,
undefined
);
});
it
(
"returns the path part correctly"
,
function
()
{
var
parts
=
parseUrl
(
"https://example.com:23/foo/bar?oh=no#gar"
);
assert
.
equal
(
parts
.
path
,
"foo/bar"
);
});
it
(
"returns undefined for the path if there isn't one"
,
function
()
{
var
parts
=
parseUrl
(
"https://example.com?oh=no#gar"
);
assert
.
equal
(
parts
.
path
,
undefined
);
});
it
(
"returns the query part correctly"
,
function
()
{
var
parts
=
parseUrl
(
"https://example.com:23/foo/bar?oh=no&ooh=ah#gar"
);
assert
.
equal
(
parts
.
query
,
"oh=no&ooh=ah"
);
});
it
(
"returns undefined for the query if there isn't one"
,
function
()
{
var
parts
=
parseUrl
(
"https://example.com#gar"
);
assert
.
equal
(
parts
.
query
,
undefined
);
});
it
(
"returns the anchor part correctly"
,
function
()
{
var
parts
=
parseUrl
(
"https://example.com:23/foo/bar?oh=no&ooh=ah#gar"
);
assert
.
equal
(
parts
.
anchor
,
"gar"
);
});
it
(
"returns undefined for the anchor if there isn't one"
,
function
()
{
var
parts
=
parseUrl
(
"https://example.com:23/foo/bar?oh=no&ooh=ah"
);
assert
.
equal
(
parts
.
anchor
,
undefined
);
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment