Fix double ? in uri bug

This commit is contained in:
Dennis Eichhorn 2018-07-06 21:33:18 +02:00
parent 1c642390e0
commit edc596aba2
2 changed files with 11 additions and 10 deletions

View File

@ -135,28 +135,29 @@
*/ */
static unique (url) static unique (url)
{ {
const parts = url.split('?'); const parts = url.replace(/\?/g, '&').split('&'),
full = parts[0];
if (parts.length >= 2) { if (parts.length > 1) {
let full = parts[1], parts.shift();
pars = full.split('&'),
comps = {}, let comps = {},
spl = null, spl = null,
length = pars.length; length = parts.length;
for (let i = 0; i < length; ++i) { for (let i = 0; i < length; ++i) {
spl = pars[i].split('='); spl = parts[i].split('=');
comps[spl[0]] = spl[1]; comps[spl[0]] = spl[1];
} }
pars = []; let pars = [];
for (let a in comps) { for (let a in comps) {
if (comps.hasOwnProperty(a)) { if (comps.hasOwnProperty(a)) {
pars.push(a + '=' + comps[a]); pars.push(a + '=' + comps[a]);
} }
} }
url = parts[0] + '?' + pars.join('&'); url = full + '?' + pars.join('&');
} }
return url; return url;

View File

@ -60,7 +60,7 @@ describe('UriFactoryTest', function ()
{ {
it('Testing global queries', function () it('Testing global queries', function ()
{ {
let uri = 'www.test-uri.com?id={@ID}&test={.mTest}&two={/path}&hash={#hash}&none=#none&found={/not}&v={/valid2}', let uri = 'www.test-uri.com?id={@ID}&test={.mTest}&two={/path}&hash={#hash}&none=#none&found={/not}?v={/valid2}',
vars = { vars = {
'@ID' : 1, '@ID' : 1,
'.mTest': 'someString', '.mTest': 'someString',