mirror of https://github.com/gorhill/uBlock.git
Fix improper handling of regex flags in search widget
Reported internally.
Potential regex flags are passed as is to RegExp contructor,
and in case of failure the query is deemed a plain text one.
Related commit:
- 8de67d22bd (diff-3f4aa453cefa49f6431f1bba3bb53a8e)
This commit is contained in:
parent
99a162f925
commit
0ec4c911dd
|
@ -172,16 +172,24 @@
|
|||
});
|
||||
}
|
||||
|
||||
// FIX: use all potential regex flags as is, and if this throws, treat
|
||||
// the query string as plain text.
|
||||
function parseQuery(query) {
|
||||
var isRE = query.match(/^\/(.*)\/([a-z]*)$/);
|
||||
if (isRE) {
|
||||
try { query = new RegExp(isRE[1], isRE[2].indexOf("i") === -1 ? "" : "i"); }
|
||||
catch(e) {} // Not a regular expression after all, do a string search
|
||||
} else {
|
||||
let isRE = query.match(/^\/(.*)\/([a-z]*)$/);
|
||||
if ( isRE ) {
|
||||
try {
|
||||
query = new RegExp(isRE[1], isRE[2]);
|
||||
}
|
||||
catch (e) {
|
||||
isRE = false;
|
||||
}
|
||||
}
|
||||
if ( isRE === false ) {
|
||||
query = parseString(query);
|
||||
}
|
||||
if (typeof query === "string" ? query === "" : query.test(""))
|
||||
if ( typeof query === 'string' ? query === '' : query.test('') ) {
|
||||
query = /x^/;
|
||||
}
|
||||
return query;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue