aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorgorhill <rhill@raymondhill.net>2015-10-16 11:42:45 -0400
committergorhill <rhill@raymondhill.net>2015-10-16 11:42:45 -0400
commit2cd47098b183995e6cc010db09f687d36a667e31 (patch)
treea7dcda167c8b7d0132c8b5b5a8ea369c125acdae /src
parent38a9504caaab7c36f98ecc81194796f6d3b3adea (diff)
downloaduBlock-2cd47098b183995e6cc010db09f687d36a667e31.zip
uBlock-2cd47098b183995e6cc010db09f687d36a667e31.tar.gz
uBlock-2cd47098b183995e6cc010db09f687d36a667e31.tar.bz2
this fixes #835
Diffstat (limited to 'src')
-rw-r--r--src/js/reverselookup-worker.js32
1 files changed, 21 insertions, 11 deletions
diff --git a/src/js/reverselookup-worker.js b/src/js/reverselookup-worker.js
index b82f9ea..946001c 100644
--- a/src/js/reverselookup-worker.js
+++ b/src/js/reverselookup-worker.js
@@ -31,25 +31,35 @@ var listEntries = Object.create(null);
// Helpers
-var rescape = function(s) {
+var reEscape = function(s) {
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
};
+var reSpecialChars = /[\*\^\t\v\n]/;
+
/******************************************************************************/
var fromNetFilter = function(details) {
var lists = [];
- var entry, pos;
+ var compiledFilter = details.compiledFilter;
+ var entry, content, pos, c;
for ( var path in listEntries ) {
entry = listEntries[path];
if ( entry === undefined ) {
continue;
}
- pos = entry.content.indexOf(details.compiledFilter);
+ content = entry.content;
+ pos = content.indexOf(compiledFilter);
if ( pos === -1 ) {
continue;
}
+ // https://github.com/gorhill/uBlock/issues/835
+ // We need an exact match.
+ c = content.charAt(pos + compiledFilter.length);
+ if ( c !== '' && reSpecialChars.test(c) === false ) {
+ continue;
+ }
lists.push({
title: entry.title,
supportURL: entry.supportURL
@@ -103,16 +113,16 @@ var fromCosmeticFilter = function(details) {
var matches = rePlainSelector.exec(filter);
if ( matches ) {
if ( matches[0] === filter ) { // simple CSS selector
- reStr = rescape('c\vlg\v' + filter);
+ reStr = reEscape('c\vlg\v' + filter);
} else { // complex CSS selector
- reStr = rescape('c\vlg+\v' + matches[0] + '\v' + filter);
+ reStr = reEscape('c\vlg+\v' + matches[0] + '\v' + filter);
}
} else if ( reHighLow.test(filter) ) { // [alt] or [title]
- reStr = rescape('c\vhlg0\v' + filter);
+ reStr = reEscape('c\vhlg0\v' + filter);
} else if ( reHighMedium.test(filter) ) { // [href^="..."]
- reStr = rescape('c\vhmg0\v') + '[a-z.-]+' + rescape('\v') + '[a-z]*' + rescape(filter);
+ reStr = reEscape('c\vhmg0\v') + '[a-z.-]+' + reEscape('\v') + '[a-z]*' + reEscape(filter);
} else { // all else
- reStr = rescape('c\vhhg0\v' + filter);
+ reStr = reEscape('c\vhhg0\v' + filter);
}
candidates[details.rawFilter] = new RegExp(reStr + '(?:\\n|$)');
@@ -125,9 +135,9 @@ var fromCosmeticFilter = function(details) {
if ( hostname !== '' ) {
for ( ;; ) {
candidates[hostname + '##' + filter] = new RegExp(
- rescape('c\vh\v') +
+ reEscape('c\vh\v') +
'\\w+' +
- rescape('\v' + hostname + '\v' + filter) +
+ reEscape('\v' + hostname + '\v' + filter) +
'(?:\\n|$)'
);
// If there is no valid domain, there won't be any other
@@ -152,7 +162,7 @@ var fromCosmeticFilter = function(details) {
if ( pos !== -1 ) {
var entity = domain.slice(0, pos);
candidates[entity + '.*##' + filter] = new RegExp(
- rescape('c\ve\v' + entity + '\v' + filter) +
+ reEscape('c\ve\v' + entity + '\v' + filter) +
'(?:\\n|$)'
);
}