Skip to content

Commit

Permalink
Merge pull request #257 from Siltaar/master
Browse files Browse the repository at this point in the history
  • Loading branch information
rodneyrehm committed Oct 13, 2015
2 parents 98ab3e7 + 5e1a209 commit c2a60f0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/URI.js
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@
} else {
data[name] = filterArrayValues(data[name], value);
}
} else if (data[name] === String(value)) {
} else if (data[name] === String(value) && (!isArray(value) || value.length === 1)) {
data[name] = undefined;
} else if (isArray(data[name])) {
data[name] = filterArrayValues(data[name], value);
Expand Down
20 changes: 18 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@
u.segment(['', '', 'foo', '', '', 'bar', '', '']);
equal(u.path(), '/foo/bar/', 'segment collapsing empty parts');

u = new URI('https://google.com')
u = new URI('https://google.com');
u.segment('//font.ttf//');
equal(u.path(), '/font.ttf', 'segment removes trailing and leading slashes');

Expand Down Expand Up @@ -867,6 +867,22 @@
u.removeQuery('bar', ['1', '3']);
equal(u.query(), 'obj=bam&bar=2', 'removing name, array');

u.query('?obj=bam&bar=1&bar=2');
u.removeQuery('bar', ['2']);
equal(u.query(), 'obj=bam&bar=1', 'removing name, singleton array');

u.removeQuery('bar', ['1']);
equal(u.query(), 'obj=bam', 'removing the last value via name, singleton array');

u.query('?foo=one&foo=two').removeQuery('foo', ['one', 'two']);
equal(u.query(), '', 'removing name, array, finishes empty');

u.query('?foo=one,two').removeQuery('foo', ['one', 'two']);
equal(u.query(), 'foo=one%2Ctwo', 'not removing name, array');

u.query('?foo=one,two').removeQuery('foo', ['one,two']);
equal(u.query(), '', 'removing name, singleton array with comma in value');

u.query('?foo=bar&foo=baz&foo=bam&obj=bam&bar=1&bar=2&bar=3');
u.removeQuery(['foo', 'bar']);
equal(u.query(), 'obj=bam', 'removing array');
Expand All @@ -877,7 +893,7 @@

u.removeQuery({ bar: 2 });
equal(u.query(), '', 'removing a non-string value');

u.query('?foo=bar&foo=baz&foo=bam&obj=bam&bar=1&bar=2&bar=3');
u.removeQuery({foo: 'bar', obj: undefined, bar: ['1', '2']});
equal(u.query(), 'foo=baz&foo=bam&bar=3', 'removing object');
Expand Down

0 comments on commit c2a60f0

Please sign in to comment.