From 187afb0f954256eb953c1ef447fccf65e6ef5dff Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 14 Nov 2022 15:45:22 +0000 Subject: [PATCH] fix: remove leading slash when parsing windows file urls (#87) --- src/parse.ts | 2 +- test/url.test.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/parse.ts b/src/parse.ts index 8f27802..d3ba214 100644 --- a/src/parse.ts +++ b/src/parse.ts @@ -26,7 +26,7 @@ export function parseURL (input: string = '', defaultProto?: string): ParsedURL const [protocol = '', auth, hostAndPath = ''] = (input.replace(/\\/g, '/').match(/([^:/]+:)?\/\/([^/@]+@)?(.*)/) || []).splice(1) const [host = '', path = ''] = (hostAndPath.match(/([^/?#]*)(.*)?/) || []).splice(1) - const { pathname, search, hash } = parsePath(path) + const { pathname, search, hash } = parsePath(path.replace(/\/(?=[A-Za-z]:)/, '')) return { protocol, diff --git a/test/url.test.ts b/test/url.test.ts index a307763..5468296 100644 --- a/test/url.test.ts +++ b/test/url.test.ts @@ -8,6 +8,7 @@ describe('parseURL', () => { { input: 'http://test.com?foo=bar', out: { auth: '', hash: '', host: 'test.com', pathname: '', protocol: 'http:', search: '?foo=bar' } }, { input: '/test', out: { hash: '', pathname: '/test', search: '' } }, { input: 'file:///home/user', out: { auth: '', hash: '', host: '', pathname: '/home/user', protocol: 'file:', search: '' } }, + { input: 'file:///C:/home/user', out: { auth: '', hash: '', host: '', pathname: 'C:/home/user', protocol: 'file:', search: '' } }, { input: 'https://host.name\\@foo.bar/meme3.php?url=http://0.0.0.0/2.svg', out: {