use another heuristic
This commit is contained in:
parent
267f096a53
commit
02a2180ccf
|
|
@ -101,24 +101,18 @@ export function urlMatches(baseURL: string | undefined, urlString: string, match
|
||||||
// Allow http(s) baseURL to match ws(s) urls.
|
// Allow http(s) baseURL to match ws(s) urls.
|
||||||
if (baseURL && /^https?:\/\//.test(baseURL) && /^wss?:\/\//.test(urlString))
|
if (baseURL && /^https?:\/\//.test(baseURL) && /^wss?:\/\//.test(urlString))
|
||||||
baseURL = baseURL.replace(/^http/, 'ws');
|
baseURL = baseURL.replace(/^http/, 'ws');
|
||||||
if (baseURL) {
|
// Resolve match relative to baseURL only if baseURL is set and match is not an absolute URL.
|
||||||
// String starting with a dot are treated as explicit relative URL.
|
// Otherwise, leave it unchanged to prevent the URL constructor from interpreting glob symbols
|
||||||
if (match.startsWith('.')) {
|
// like ?, {, and }, which could alter the pattern.
|
||||||
match = constructURLBasedOnBaseURL(baseURL, match);
|
if (baseURL && !parseURL(match))
|
||||||
} else {
|
match = constructURLBasedOnBaseURL(baseURL, match);
|
||||||
// We cannot pass `match` as the relative URL as regex symbols would be misinterpreted.
|
|
||||||
const relativeBase = match.startsWith('/') ? '/' : '.';
|
|
||||||
let prefix = constructURLBasedOnBaseURL(baseURL, relativeBase);
|
|
||||||
if (prefix !== relativeBase) {
|
|
||||||
if (match.startsWith('/') && prefix.endsWith('/'))
|
|
||||||
prefix = prefix.substring(0, prefix.length - 1);
|
|
||||||
match = prefix + match;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (isString(match))
|
if (isString(match)) {
|
||||||
|
const tryWithoutTrailingSlash = urlString.endsWith('/') && !match.endsWith('/');
|
||||||
match = globToRegex(match);
|
match = globToRegex(match);
|
||||||
|
if (tryWithoutTrailingSlash && match.test(urlString.substring(0, urlString.length - 1)))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (isRegExp(match))
|
if (isRegExp(match))
|
||||||
return match.test(urlString);
|
return match.test(urlString);
|
||||||
const url = parseURL(urlString);
|
const url = parseURL(urlString);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue