Open dannypurcell opened 9 years ago
I'm not sure I'd go as far as calling this a bug, but it certainly is not expected behavior either. I'll leave this issue open for the community to discuss.
Hi guys I faced with similar issue and I believe it is a bug.
Example 1
var location = new URI('http://example.com/?a=2&a=2');
location.addSearch('b', '3');
console.log(location.toString());
// Actual result: http://example.com/?a=2&b=3
// Expected result: http://example.com/?a=2&a=2&b=3
I do not expect that on adding new param something will be removed.
Example 2
var location = new URI('http://example.com/?a=2&a=2');
var query = location.search(true);
console.log(query); // { a: [ '2', '2' ] }
location.search(query);
console.log(location.toString());
// Actual result: http://example.com/?a=2
// Expected result: http://example.com/?a=2&a=2
I found that there is duplicateQueryParameters
param which is false by default. But seems it works only on set query, not on get. When I receive query object using .search(true)
(it contains duplicated) I expect that passing exactly the same object without modifications to .search(obj)
will give me the same url, but it returns different.
You can set URI.duplicateQueryParameters = true
to have this behavior globally, or use loc.duplicateQueryParameters(true)
to make it a per instance thing. The default is false
for historic reasons and should probably be changed to true
in the next major release
Yep, with duplicateQueryParameters = true
everything works as expected. Thanks :)
Thank you for releasing this fine project for all of us to benefit from!
While adjusting a page url with removeSearch() I noticed a slightly surprising side-effect. I thought it worth posting incase this was not the intended behavior.
Removing a key from the query string appears to also have the effect of removing duplicate entries of other keys in the query string.