1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-15 15:32:28 +02:00

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:
Raymond Hill 2020-06-13 11:13:48 -04:00
parent 99a162f925
commit 0ec4c911dd
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -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;
}