Skip to content
This repository was archived by the owner on Dec 19, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions iron-query-params.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,21 @@
_encodeParams: function(params) {
var encodedParams = [];
for (var key in params) {
var value = params[key];
if (value === '') {
encodedParams.push(encodeURIComponent(key));
} else if (value) {
encodedParams.push(
encodeURIComponent(key) +
'=' +
encodeURIComponent(value.toString())
);
var values = params[key];

if (values) {
values.forEach(value => {
if (value === '') {
encodedParams.push(encodeURIComponent(key));
} else if (value.length > 0) {

encodedParams.push(
encodeURIComponent(key) +
'=' +
encodeURIComponent(value.toString())
);
}
});
}
}
return encodedParams.join('&');
Expand All @@ -79,8 +85,11 @@
for (var i = 0; i < paramList.length; i++) {
var param = paramList[i].split('=');
if (param[0]) {
params[decodeURIComponent(param[0])] =
decodeURIComponent(param[1] || '');
var param0 = decodeURIComponent(param[0]);
if (!params[param0]) {
params[param0] = [];
}
params[param0].push(decodeURIComponent(param[1] || ''));
}
}
return params;
Expand Down
5 changes: 3 additions & 2 deletions test/integration.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@
expect(ironLocationQuery).to.contain(ironLocation.query);
expect(ironLocationQuery).to.contain(ironQueryParams.paramsString);
if (plainTextQuery) {
expect('').to.be.equal(ironQueryParams.paramsObject[plainTextQuery])
expect(1).to.be.equal(ironQueryParams.paramsObject[plainTextQuery].length)
expect('').to.be.equal(ironQueryParams.paramsObject[plainTextQuery][0])
} else {
expect(ironQueryParams.paramsObject[plainTextQuery]).to.be.undefined;
}
Expand Down Expand Up @@ -122,7 +123,7 @@
}

var newParamsObject = {};
newParamsObject[plainTextQuery] = '';
newParamsObject[plainTextQuery] = [''];

ironQueryParams.paramsObject = newParamsObject;
expect(encodedQueries).to.contain(window.location.search);
Expand Down
18 changes: 11 additions & 7 deletions test/iron-query-params.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,34 @@
// Check the mapping from paramsString to paramsObject.
paramsElem.paramsString = 'greeting=hello&target=world';
expect(paramsElem.paramsObject).to.deep.equal(
{greeting: 'hello', target: 'world'});
{greeting: ['hello'], target: ['world']});

// Check the mapping from paramsObject back to paramsString.
paramsElem.set('paramsObject.another', 'key');
paramsElem.set('paramsObject.another', ['key']);
expect(paramsElem.paramsString).to.be.equal(
'greeting=hello&target=world&another=key');
});
test('encoding of params', function() {
var mappings = [
{
string: 'a=b',
object: {'a': 'b'}
object: {'a': ['b']}
},
{
string: 'a=b&a=c',
object: {'a': ['b','c']}
},
{
string: 'debug&ok',
object: {'debug': '', 'ok': ''}
object: {'debug': [''], 'ok': ['']}
},
{
string: 'monster%20kid%3A=%F0%9F%98%BF&quotes=%27%27',
object: {'monster kid:': '😿', 'quotes': '\'\''}
object: {'monster kid:': ['😿'], 'quotes': ['\'\'']}
},
{
string: 'yes%2C%20ok?%20what%20is%20up%20with%20%CB%9Athiiis%CB%9A=%E2%98%83',
object: {'yes, ok? what is up with ˚thiiis˚': '☃'}
object: {'yes, ok? what is up with ˚thiiis˚': ['☃']}
},
];

Expand All @@ -94,7 +98,7 @@
// Check the mapping for querystrings with + instead of %20.
paramsElem.paramsString = 'key=value+with+spaces';
expect(paramsElem.paramsObject).to.deep.equal(
{key: 'value with spaces'});
{key: ['value with spaces']});
});
});

Expand Down