mirror of
https://github.com/bitwarden/browser
synced 2025-12-19 09:43:23 +00:00
[PM-1426] Refactor uri matching (#5003)
* Move URI matching logic into uriView * Fix url parsing: always assign default protocol, otherwise no protocol with port is parsed incorrectly * Codescene: refactor domain matching logic
This commit is contained in:
@@ -379,15 +379,7 @@ export class Utils {
|
||||
|
||||
uriString = uriString.trim();
|
||||
|
||||
let url = Utils.getUrlObject(uriString);
|
||||
if (url == null) {
|
||||
const hasHttpProtocol =
|
||||
uriString.indexOf("http://") === 0 || uriString.indexOf("https://") === 0;
|
||||
if (!hasHttpProtocol && uriString.indexOf(".") > -1) {
|
||||
url = Utils.getUrlObject("http://" + uriString);
|
||||
}
|
||||
}
|
||||
return url;
|
||||
return Utils.getUrlObject(uriString);
|
||||
}
|
||||
|
||||
static camelToPascalCase(s: string) {
|
||||
@@ -542,22 +534,21 @@ export class Utils {
|
||||
}
|
||||
|
||||
private static getUrlObject(uriString: string): URL {
|
||||
// All the methods below require a protocol to properly parse a URL string
|
||||
// Assume http if no other protocol is present
|
||||
const hasProtocol = uriString.indexOf("://") > -1;
|
||||
if (!hasProtocol && uriString.indexOf(".") > -1) {
|
||||
uriString = "http://" + uriString;
|
||||
} else if (!hasProtocol) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
if (nodeURL != null) {
|
||||
return new nodeURL.URL(uriString);
|
||||
} else if (typeof URL === "function") {
|
||||
return new URL(uriString);
|
||||
} else if (typeof window !== "undefined") {
|
||||
const hasProtocol = uriString.indexOf("://") > -1;
|
||||
if (!hasProtocol && uriString.indexOf(".") > -1) {
|
||||
uriString = "http://" + uriString;
|
||||
} else if (!hasProtocol) {
|
||||
return null;
|
||||
}
|
||||
const anchor = window.document.createElement("a");
|
||||
anchor.href = uriString;
|
||||
return anchor as any;
|
||||
}
|
||||
|
||||
return new URL(uriString);
|
||||
} catch (e) {
|
||||
// Ignore error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user