diff --git a/src/parse.ts b/src/parse.ts index 8cebd49..e8a4866 100644 --- a/src/parse.ts +++ b/src/parse.ts @@ -25,7 +25,7 @@ export function parseURL (input: string = '', defaultProto?: string): ParsedURL } const [protocol = '', auth, hostAndPath] = (input.match(/([^:/]+:)?\/\/([^/@]+@)?(.*)/) || []).splice(1) - const [host = '', path = ''] = (hostAndPath.match(/([^/]*)(.*)?/) || []).splice(1) + const [host = '', path = ''] = (hostAndPath.match(/([^/?]*)(.*)?/) || []).splice(1) const { pathname, search, hash } = parsePath(path) return { diff --git a/test/query.test.ts b/test/query.test.ts index cb7fb73..5f39078 100644 --- a/test/query.test.ts +++ b/test/query.test.ts @@ -19,7 +19,8 @@ describe('withQuery', () => { query: { str: '&', str2: '%26' }, out: '/?str=%26&str2=%2526' }, - { input: '/?x=1,2,3', query: { y: '1,2,3' }, out: '/?x=1,2,3&y=1,2,3' } + { input: '/?x=1,2,3', query: { y: '1,2,3' }, out: '/?x=1,2,3&y=1,2,3' }, + { input: 'http://a.com?v=1', query: { x: 2 }, out: 'http://a.com?v=1&x=2' } ] for (const t of tests) { diff --git a/test/url.test.ts b/test/url.test.ts index a40d9c1..dc77ce1 100644 --- a/test/url.test.ts +++ b/test/url.test.ts @@ -4,6 +4,7 @@ describe('parseURL', () => { const tests = [ { input: '//test', out: { auth: '', hash: '', host: 'test', pathname: '', protocol: '', search: '' } }, { input: 'https://test.com', out: { auth: '', hash: '', host: 'test.com', pathname: '', protocol: 'https:', search: '' } }, + { 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: '' } } ]