Skip to content

Commit

Permalink
feature(query): fixing parsing of "?foo&foo=1" - closes #220
Browse files Browse the repository at this point in the history
  • Loading branch information
rodneyrehm committed Jun 23, 2015
1 parent ed8955c commit fc63b02
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ URI.js is published under the [MIT license](http://www.opensource.org/licenses/m

## Changelog ##

### master (will become 1.15.2) ###

* fixing `URI.parseQuery()` to accept `?foo&foo=bar` - [Issue #220](https://github.com/medialize/URI.js/issues/220)

### 1.15.1 (April 5th 2015) ###

* fixing `URI()` to match behavior of `new URI()` (caused by [#196](https://github.com/medialize/URI.js/issues/196)) - [Issue #205](https://github.com/medialize/URI.js/issues/205)
Expand Down
2 changes: 1 addition & 1 deletion src/URI.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@
value = v.length ? URI.decodeQuery(v.join('='), escapeQuerySpace) : null;

if (hasOwn.call(items, name)) {
if (typeof items[name] === 'string') {
if (typeof items[name] === 'string' || items[name] === null) {
items[name] = [items[name]];
}

Expand Down
16 changes: 16 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,22 @@
equal(u.query(), 'foo', 'search: ""');
equal(u.search(), '?foo', 'search: "" - query');

u.search('foo=&foo=bar');
equal(u.query(), 'foo=&foo=bar', 'search: foo=&foo=bar');
equal(JSON.stringify(u.query(true)), JSON.stringify({foo: ['', 'bar']}), 'parsed query: {foo:["", "bar"]}');

u.search('foo=bar&foo=');
equal(u.query(), 'foo=bar&foo=', 'search: foo=bar&foo=');
equal(JSON.stringify(u.query(true)), JSON.stringify({foo: ['bar', '']}), 'parsed query: {foo:["bar", ""]}');

u.search('foo=bar&foo');
equal(u.query(), 'foo=bar&foo', 'search: foo=bar&foo');
equal(JSON.stringify(u.query(true)), JSON.stringify({foo: ['bar', null]}), 'parsed query: {foo:["bar", null]}');

u.search('foo&foo=bar');
equal(u.query(), 'foo&foo=bar', 'search: foo&foo=bar');
equal(JSON.stringify(u.query(true)), JSON.stringify({foo: [null, 'bar']}), 'parsed query: {foo:[null, "bar"]}');

// parsing empty query
var t;
t = u.query('?').query(true);
Expand Down

0 comments on commit fc63b02

Please sign in to comment.