mirror of https://github.com/gorhill/uBlock.git
fix not discarding empty hostnames: 912af3284d (commitcomment-31608689)
This commit is contained in:
parent
0f8f999f99
commit
90c073882e
|
@ -51,12 +51,11 @@
|
||||||
**/
|
**/
|
||||||
|
|
||||||
µBlock.staticExtFilteringEngine = (function() {
|
µBlock.staticExtFilteringEngine = (function() {
|
||||||
var µb = µBlock,
|
const µb = µBlock;
|
||||||
reHostnameSeparator = /\s*,\s*/,
|
const reHasUnicode = /[^\x00-\x7F]/;
|
||||||
reHasUnicode = /[^\x00-\x7F]/,
|
const reParseRegexLiteral = /^\/(.+)\/([imu]+)?$/;
|
||||||
reParseRegexLiteral = /^\/(.+)\/([imu]+)?$/,
|
const emptyArray = [];
|
||||||
emptyArray = [],
|
const parsed = {
|
||||||
parsed = {
|
|
||||||
hostnames: [],
|
hostnames: [],
|
||||||
exception: false,
|
exception: false,
|
||||||
suffix: ''
|
suffix: ''
|
||||||
|
@ -64,12 +63,12 @@
|
||||||
|
|
||||||
// To be called to ensure no big parent string of a string slice is
|
// To be called to ensure no big parent string of a string slice is
|
||||||
// left into memory after parsing filter lists is over.
|
// left into memory after parsing filter lists is over.
|
||||||
var resetParsed = function() {
|
const resetParsed = function() {
|
||||||
parsed.hostnames = [];
|
parsed.hostnames = [];
|
||||||
parsed.suffix = '';
|
parsed.suffix = '';
|
||||||
};
|
};
|
||||||
|
|
||||||
var isValidCSSSelector = (function() {
|
const isValidCSSSelector = (function() {
|
||||||
var div = document.createElement('div'),
|
var div = document.createElement('div'),
|
||||||
matchesFn;
|
matchesFn;
|
||||||
// Keep in mind:
|
// Keep in mind:
|
||||||
|
@ -109,7 +108,7 @@
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
||||||
var isBadRegex = function(s) {
|
const isBadRegex = function(s) {
|
||||||
try {
|
try {
|
||||||
void new RegExp(s);
|
void new RegExp(s);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
|
@ -119,23 +118,34 @@
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
var translateAdguardCSSInjectionFilter = function(suffix) {
|
const translateAdguardCSSInjectionFilter = function(suffix) {
|
||||||
var matches = /^([^{]+)\{([^}]+)\}$/.exec(suffix);
|
var matches = /^([^{]+)\{([^}]+)\}$/.exec(suffix);
|
||||||
if ( matches === null ) { return ''; }
|
if ( matches === null ) { return ''; }
|
||||||
return matches[1].trim() + ':style(' + matches[2].trim() + ')';
|
return matches[1].trim() + ':style(' + matches[2].trim() + ')';
|
||||||
};
|
};
|
||||||
|
|
||||||
var toASCIIHostnames = function(hostnames) {
|
const hostnamesFromPrefix = function(s) {
|
||||||
var i = hostnames.length;
|
const hostnames = [];
|
||||||
while ( i-- ) {
|
const hasUnicode = reHasUnicode.test(s);
|
||||||
var hostname = hostnames[i];
|
let beg = 0;
|
||||||
hostnames[i] = hostname.charCodeAt(0) === 0x7E /* '~' */ ?
|
while ( beg < s.length ) {
|
||||||
'~' + punycode.toASCII(hostname.slice(1)) :
|
let end = s.indexOf(',', beg);
|
||||||
punycode.toASCII(hostname);
|
if ( end === -1 ) { end = s.length; }
|
||||||
|
let hostname = s.slice(beg, end).trim();
|
||||||
|
if ( hostname.length !== 0 ) {
|
||||||
|
if ( hasUnicode ) {
|
||||||
|
hostname = hostname.charCodeAt(0) === 0x7E /* '~' */
|
||||||
|
? '~' + punycode.toASCII(hostname.slice(1))
|
||||||
|
: punycode.toASCII(hostname);
|
||||||
}
|
}
|
||||||
|
hostnames.push(hostname);
|
||||||
|
}
|
||||||
|
beg = end + 1;
|
||||||
|
}
|
||||||
|
return hostnames;
|
||||||
};
|
};
|
||||||
|
|
||||||
var compileProceduralSelector = (function() {
|
const compileProceduralSelector = (function() {
|
||||||
var reProceduralOperator = new RegExp([
|
var reProceduralOperator = new RegExp([
|
||||||
'^(?:',
|
'^(?:',
|
||||||
[
|
[
|
||||||
|
@ -713,11 +723,7 @@
|
||||||
if ( lpos === 0 ) {
|
if ( lpos === 0 ) {
|
||||||
parsed.hostnames = emptyArray;
|
parsed.hostnames = emptyArray;
|
||||||
} else {
|
} else {
|
||||||
let prefix = raw.slice(0, lpos);
|
parsed.hostnames = hostnamesFromPrefix(raw.slice(0, lpos));
|
||||||
parsed.hostnames = prefix.split(reHostnameSeparator);
|
|
||||||
if ( reHasUnicode.test(prefix) ) {
|
|
||||||
toASCIIHostnames(parsed.hostnames);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Backward compatibility with deprecated syntax.
|
// Backward compatibility with deprecated syntax.
|
||||||
|
|
Loading…
Reference in New Issue