Have utilStringQs advance past any leading '?' or '#' characters

This lets us remove a bunch of substring(1) and +1 from the code.
This commit is contained in:
Bryan Housel
2020-02-20 17:09:54 -05:00
parent 1f4fe57d8b
commit dc7fba4bf8
10 changed files with 61 additions and 38 deletions
+1 -1
View File
@@ -21,7 +21,7 @@ describe('iD.serviceNominatim', function() {
});
function query(url) {
return iD.utilStringQs(url.substring(url.indexOf('?') + 1));
return iD.utilStringQs(url.substring(url.indexOf('?')));
}
+1 -1
View File
@@ -21,7 +21,7 @@ describe('iD.serviceOsmWikibase', function () {
function query(url) {
return iD.utilStringQs(url.substring(url.indexOf('?') + 1));
return iD.utilStringQs(url.substring(url.indexOf('?')));
}
function adjust(params, data) {
+1 -1
View File
@@ -31,7 +31,7 @@ describe('iD.serviceTaginfo', function() {
});
function query(url) {
return iD.utilStringQs(url.substring(url.indexOf('?') + 1));
return iD.utilStringQs(url.substring(url.indexOf('?')));
}
+2
View File
@@ -7,6 +7,8 @@ for (var k in iD.services) { delete iD.services[k]; }
// Run without data for speed (tests which need data can set it up themselves)
// Initializing `coreContext` will try loading the English locale strings:
iD.data.locale_en = { en: {} };
// Initializing `coreContext` initializes `_background`, which tries loading:
iD.data.imagery = [];
// Initializing `coreContext` initializes `_presets`, which tries loading:
+20 -3
View File
@@ -79,9 +79,26 @@ describe('iD.util', function() {
});
it('utilStringQs', function() {
expect(iD.utilStringQs('foo=bar')).to.eql({foo: 'bar'});
expect(iD.utilStringQs('foo=bar&one=2')).to.eql({foo: 'bar', one: '2' });
expect(iD.utilStringQs('')).to.eql({});
it('splits a parameter string into k=v pairs', function() {
expect(iD.utilStringQs('foo=bar')).to.eql({foo: 'bar'});
expect(iD.utilStringQs('foo=bar&one=2')).to.eql({foo: 'bar', one: '2' });
expect(iD.utilStringQs('')).to.eql({});
});
it('trims leading # if present', function() {
expect(iD.utilStringQs('#foo=bar')).to.eql({foo: 'bar'});
expect(iD.utilStringQs('#foo=bar&one=2')).to.eql({foo: 'bar', one: '2' });
expect(iD.utilStringQs('#')).to.eql({});
});
it('trims leading ? if present', function() {
expect(iD.utilStringQs('?foo=bar')).to.eql({foo: 'bar'});
expect(iD.utilStringQs('?foo=bar&one=2')).to.eql({foo: 'bar', one: '2' });
expect(iD.utilStringQs('?')).to.eql({});
});
it('trims leading #? if present', function() {
expect(iD.utilStringQs('#?foo=bar')).to.eql({foo: 'bar'});
expect(iD.utilStringQs('#?foo=bar&one=2')).to.eql({foo: 'bar', one: '2' });
expect(iD.utilStringQs('#?')).to.eql({});
});
});
it('utilQsString', function() {