Skip to content

Commit

Permalink
fix: remove leading slash when parsing windows file urls (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Nov 14, 2022
1 parent f8900d5 commit 187afb0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/parse.ts
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions test/url.test.ts
Expand Up @@ -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: {
Expand Down

0 comments on commit 187afb0

Please sign in to comment.