diff --git a/package.json b/package.json index 0313490..3779edb 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,8 @@ "test:browser": "karmatic", "test:node": "jest", "pretest": "yarn run build", - "test": "jest && karmatic" + "test": "jest && karmatic", + "release": "release-it" }, "author": "Janicklas Ralph", "license": "Apache-2.0", diff --git a/src/index.test.js b/src/index.test.js index 8ba0675..92dcd74 100644 --- a/src/index.test.js +++ b/src/index.test.js @@ -108,6 +108,24 @@ describe('Basic parse and format:', () => { }); }); +parseTestsWithQueryString = { + ...parseTestsWithQueryString, + '/example?query=size:10': { + protocol: null, + slashes: null, + auth: null, + host: null, + port: null, + hostname: null, + hash: null, + search: '?query=size:10', + query: { query: 'size:10' }, + pathname: '/example', + path: '/example?query=size:10', + href: '/example?query=size:10', + }, +}; + describe('With querystring:', () => { Object.keys(parseTestsWithQueryString).forEach(function (u) { it(`parse(${u}):`, () => { diff --git a/src/parse.js b/src/parse.js index 16c6d05..004f545 100644 --- a/src/parse.js +++ b/src/parse.js @@ -83,7 +83,7 @@ export default function (urlStr, parseQs = false, slashesDenoteHost = false) { } // If port is 80 we change it to 8000 and undo it later - let portMatch = urlStr.match(/(:[0-9]+)/); + let portMatch = (slashesMatch ? slashesMatch[1] : urlStr).match(/(:[0-9]+)/); let portSuffix = ''; if (portMatch && portMatch[1] && portMatch[1].length === 3) {