From 8fb6e0af5a2226290c33624efc55bd4f4758866a Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 24 Aug 2023 18:41:33 +0200 Subject: [PATCH] fix: normalize leading space --- src/parse.ts | 5 +++-- test/parse.test.ts | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/parse.ts b/src/parse.ts index ff0914be..0ab41d14 100644 --- a/src/parse.ts +++ b/src/parse.ts @@ -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(/([^#/?]*)(.*)?/) || [] diff --git a/test/parse.test.ts b/test/parse.test.ts index 1f4516eb..0eb8b02a 100644 --- a/test/parse.test.ts +++ b/test/parse.test.ts @@ -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: "", }, }, ];