Skip to content

Commit c2974ed

Browse files
committed
Realign _.toQuery with jQuery 3 $.param (#218)
1 parent 7bb8c22 commit c2974ed

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

test/util.strings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ $(document).ready(function() {
4141

4242
QUnit.test('toQuery', function(assert) {
4343
var obj = {'foo&bar': 'baz', 'test': 'total success', 'nested': {'works': 'too'}, 'isn\'t': ['that', 'cool?']};
44-
assert.equal(_.toQuery(obj), 'foo%26bar=baz&test=total+success&nested%5Bworks%5D=too&isn\'t%5B%5D=that&isn\'t%5B%5D=cool%3F', 'can convert a hash to a query string');
44+
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');
4545
assert.equal(_.toQuery(obj), jQuery.param(obj), 'query serialization matchs jQuery.param()');
4646
});
4747

underscore.util.strings.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@
1717

1818
// No reason to create regex more than once
1919
var plusRegex = /\+/g;
20-
var spaceRegex = /\%20/g;
2120
var bracketRegex = /(?:([^\[]+))|(?:\[(.*?)\])/g;
2221

2322
var urlDecode = function(s) {
2423
return decodeURIComponent(s.replace(plusRegex, '%20'));
2524
};
2625
var urlEncode = function(s) {
27-
return encodeURIComponent(s).replace(spaceRegex, '+');
26+
return encodeURIComponent(s);
2827
};
2928

3029
var buildParams = function(prefix, val, top) {

0 commit comments

Comments
 (0)