Skip to content

Commit

Permalink
fix: ignore whitespace when detecting protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Aug 24, 2023
1 parent d5773fe commit b1699e2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export function isRelative(inputString: string) {
return ["./", "../"].some((string_) => inputString.startsWith(string_));
}

const PROTOCOL_STRICT_REGEX = /^\w{2,}:([/\\]{1,2})/;
const PROTOCOL_REGEX = /^\w{2,}:([/\\]{2})?/;
const PROTOCOL_STRICT_REGEX = /^[\s\w\0]{2,}:([/\\]{1,2})/;
const PROTOCOL_REGEX = /^[\s\w\0]{2,}:([/\\]{2})?/;
const PROTOCOL_RELATIVE_REGEX = /^([/\\]\s*){2,}[^/\\]/;

export interface HasProtocolOptions {
Expand Down
3 changes: 3 additions & 0 deletions test/utilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ describe("hasProtocol", () => {

// Has protocol (non strict)
{ input: "tel:", out: [true, false, true] },
{ input: "javascript:alert(true)", out: [true, false, true] },
{ input: " javascript:alert(true)", out: [true, false, true] },
{ input: "\0javascript:alert(true)", out: [true, false, true] },
{ input: "tel:123456", out: [true, false, true] },
{ input: "mailto:support@example.com", out: [true, false, true] },

Expand Down

0 comments on commit b1699e2

Please sign in to comment.