Skip to content
Merged
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
3 changes: 3 additions & 0 deletions test/util.strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ $(document).ready(function() {
var obj = {'foo&bar': 'baz', 'test': 'total success', 'nested': {'works': 'too'}, 'isn\'t': ['that', 'cool?']};
assert.equal(_.toQuery(obj), 'foo%26bar=baz&test=total%20success&nested%5Bworks%5D=too&isn\'t%5B%5D=that&isn\'t%5B%5D=cool%3F', 'can convert a hash to a query string');
assert.equal(_.toQuery(obj), jQuery.param(obj), 'query serialization matchs jQuery.param()');
assert.equal(_.toQuery({a: []}), '', 'empty array params produce the empty string');
assert.equal(_.toQuery({a: [], b: []}), '', 'multiple empty array params do not lead to spurious ampersands');
assert.equal(_.toQuery({a: null, b: undefined}), 'a=null&b=undefined', 'respects null and undefined');
});

QUnit.test('strContains', function(assert) {
Expand Down
8 changes: 4 additions & 4 deletions underscore.util.strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
var buildParams = function(prefix, val, top) {
if (_.isUndefined(top)) top = true;
if (_.isArray(val)) {
return _.map(val, function(value, key) {
return _.compact(_.map(val, function(value, key) {
return buildParams(top ? key : prefix + '[]', value, false);
}).join('&');
})).join('&');
} else if (_.isObject(val)) {
return _.map(val, function(value, key) {
return _.compact(_.map(val, function(value, key) {
return buildParams(top ? key : prefix + '[' + key + ']', value, false);
}).join('&');
})).join('&');
} else {
return urlEncode(prefix) + '=' + urlEncode(val);
}
Expand Down