Fix + symbol appearing in changeset comments from external tools (#10766)

This commit is contained in:
Kyℓe Hensel
2025-02-13 00:13:15 +11:00
committed by GitHub
parent f3a985f78b
commit 6328776df1
5 changed files with 42 additions and 34 deletions
+9
View File
@@ -79,4 +79,13 @@ describe('iD.behaviorHash', function () {
done();
}, 600);
});
it('accepts default changeset comment as hash parameter', function () {
window.location.hash = '#comment=foo+bar%20%2B1';
var container = d3.select(document.createElement('div'));
context = iD.coreContext().assetPath('../dist/').init().container(container);
iD.behaviorHash(context);
expect(context.defaultChangesetComment()).to.eql('foo bar +1');
hash.off();
});
});
+11 -7
View File
@@ -80,31 +80,35 @@ describe('iD.util', function() {
describe('utilStringQs', function() {
it('splits a parameter string into k=v pairs', function() {
expect(iD.utilStringQs('')).to.eql({});
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({});
expect(iD.utilStringQs('foo=bar baz')).to.eql({foo: 'bar baz'});
expect(iD.utilStringQs('foo=bar+baz')).to.eql({foo: 'bar baz'});
expect(iD.utilStringQs('foo=bar%20baz')).to.eql({foo: 'bar baz'});
});
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' });
});
it('supports both + and %20 for escaping spaces', function() {
expect(iD.utilStringQs('#?foo=a+b%20c')).to.eql({foo: 'a b c'});
expect(iD.utilStringQs('#?')).to.eql({});
});
});
it('utilQsString', function() {
expect(iD.utilQsString({})).to.eql('');
expect(iD.utilQsString({ foo: 'bar' })).to.eql('foo=bar');
expect(iD.utilQsString({ foo: 'bar', one: 2 })).to.eql('foo=bar&one=2');
expect(iD.utilQsString({})).to.eql('');
expect(iD.utilQsString({ foo: 'bar baz' })).to.be.oneOf(['foo=bar%20baz', 'foo=bar+baz']);
expect(iD.utilQsString({ foo: 'bar/baz' })).to.eql('foo=bar%2Fbaz');
expect(iD.utilQsString({ foo: 'bar/baz' }, true)).to.eql('foo=bar/baz');
});
describe('utilEditDistance', function() {