Skip to content

Commit

Permalink
[Fix] format: encode query string keys
Browse files Browse the repository at this point in the history
Fixes #67
  • Loading branch information
ljharb committed Sep 14, 2023
1 parent a6ddc4e commit c3e0a5d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
15 changes: 14 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,19 @@ var formatTests = {
hash: '#frag',
search: '?abc=the#1?&foo=bar',
pathname: '/fooA100%mBr'
},

// colons in keys
'https://cdpn.io/test?custom%3Aid=12': {
href: 'https://cdpn.io/test?custom%3Aid=12',
protocol: 'https:',
hostname: 'cdpn.io',
hash: '',
search: '?custom%3Aid=12',
pathname: '/test',
query: {
'custom:id': '12'
}
}
};

Expand Down Expand Up @@ -2029,7 +2042,7 @@ relativeTests.forEach(function (relativeTest) {
});

test('format with querystring', function () {
var obj = { protocol: 'https:', host: 'google.com', pathname: 'test', query: { message: ['value1', 'value2'] } };
var obj = { protocol: 'https:', host: 'google.com', pathname: 'test', query: { message: ['value1', 'value2'], 'custom:id': 12 } };

var actual = url.format(obj);
var expected = nodeURL.format(obj);
Expand Down
1 change: 0 additions & 1 deletion url.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,6 @@ Url.prototype.format = function () {
if (this.query && typeof this.query === 'object' && Object.keys(this.query).length) {
query = querystring.stringify(this.query, {
arrayFormat: 'repeat',
encodeValuesOnly: true,
addQueryPrefix: false
});
}
Expand Down

0 comments on commit c3e0a5d

Please sign in to comment.