Skip to content

Commit

Permalink
fix: normalize leading space
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Aug 24, 2023
1 parent 47c2236 commit 8fb6e0a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ export function parseURL(input = "", defaultProto?: string): ParsedURL {
}

const [protocol = "", auth, hostAndPath = ""] = (
input.replace(/\\/g, "/").match(/([\s\w\0+.-]{2,}:)?\/\/([^/@]+@)?(.*)/) ||
[]
input
.replace(/\\/g, "/")
.match(/^[\s\0]*([\w+.-]{2,}:)?\/\/([^/@]+@)?(.*)/) || []
).splice(1);
const [host = "", path = ""] = (
hostAndPath.match(/([^#/?]*)(.*)?/) || []
Expand Down
6 changes: 3 additions & 3 deletions test/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ describe("parseURL", () => {
},
},
{
input: "\0https://domain.test:3000#owo",
input: "\0https://invalid.com",
out: {
protocol: "https:",
auth: "",
host: "domain.test:3000",
host: "invalid.com",
pathname: "",
search: "",
hash: "#owo",
hash: "",
},
},
];
Expand Down

0 comments on commit 8fb6e0a

Please sign in to comment.