Skip to content

Commit

Permalink
fix: parse more data-type protocols
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Aug 24, 2023
1 parent b1699e2 commit 2cd4647
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export interface ParsedHost {
* @returns A parsed URL object.
*/
export function parseURL(input = "", defaultProto?: string): ParsedURL {
const dataMatch = input.match(/^(data:|blob:)/);
const dataMatch = input.match(/^(blob|data|javascript|vbscript):/);
if (dataMatch) {
const proto = dataMatch[1];
const proto = dataMatch[0];
return {
protocol: proto,
pathname: input.slice(proto.length),
Expand Down
12 changes: 12 additions & 0 deletions test/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ describe("parseURL", () => {
search: "?url=http://0.0.0.0/2.svg",
},
},
{
input: "javascript:alert('hello')",
out: {
protocol: "javascript:",
auth: "",
host: "",
href: "javascript:alert('hello')",
pathname: "alert('hello')",
search: "",
hash: "",
},
},
{
input: "https://domain.test:3000#owo",
out: {
Expand Down

0 comments on commit 2cd4647

Please sign in to comment.