Work around unsupported RegExp lookbehind in WebKit. (#85)

* Work around unsupported RegExp lookbehind in WebKit.

* Update static/find/find.js

Co-authored-by: Mario Carneiro <di.gama@gmail.com>

Co-authored-by: Mario Carneiro <di.gama@gmail.com>
main
Ruben Van de Velde 2022-10-20 18:21:33 +02:00 committed by GitHub
parent d7fe046e94
commit 153982f982
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 3 deletions

View File

@ -17,14 +17,27 @@
import { DeclarationDataCenter } from "../declaration-data.js"; import { DeclarationDataCenter } from "../declaration-data.js";
function leanFriendlyRegExp(c) {
try {
return new RegExp("(?<!«[^»]*)" + c);
} catch (e) {
if (e instanceof SyntaxError) {
// Lookbehind is not implemented yet in WebKit: https://bugs.webkit.org/show_bug.cgi?id=174931
// Fall back to less friendly regex.
return new RegExp(c);
}
throw e;
}
}
/** /**
* We don't use browser's default hash and searchParams in case Lean declaration name * We don't use browser's default hash and searchParams in case Lean declaration name
* can be like `«#»`, rather we manually handle the `window.location.href` with regex. * can be like `«#»`, rather we manually handle the `window.location.href` with regex.
*/ */
const LEAN_FRIENDLY_URL_REGEX = /^[^?#]+(?:\?((?:[^«#»]|«.*»)*))?(?:#(.*))?$/; const LEAN_FRIENDLY_URL_REGEX = /^[^?#]+(?:\?((?:[^«#»]|«.*»)*))?(?:#(.*))?$/;
const LEAN_FRIENDLY_AND_SEPARATOR = /(?<!«[^»]*)&/; const LEAN_FRIENDLY_AND_SEPARATOR = leanFriendlyRegExp("&");
const LEAN_FRIENDLY_EQUAL_SEPARATOR = /(?<!«[^»]*)=/; const LEAN_FRIENDLY_EQUAL_SEPARATOR = leanFriendlyRegExp("=");
const LEAN_FRIENDLY_SLASH_SEPARATOR = /(?<!«[^»]*)\//; const LEAN_FRIENDLY_SLASH_SEPARATOR = leanFriendlyRegExp("/");
const [_, query, fragment] = LEAN_FRIENDLY_URL_REGEX.exec(window.location.href); const [_, query, fragment] = LEAN_FRIENDLY_URL_REGEX.exec(window.location.href);
const queryParams = new Map( const queryParams = new Map(