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
1 changed files with 14 additions and 6 deletions

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