Permalink
Browse files

url: `url.format()` encodes all `#` in `search`

This commit fixes an error where only the first occurrence of `#` in
`search` parameter is URL encoded, and subsequent occurrences are not.

Also added a test for the case.

Fixes: #8064
PR-URL: #8072
Reviewed-By: James M Snell <jasnell@gmail.com>

 Conflicts:
	test/parallel/test-url.js
  • Loading branch information...
imyller authored and Fishrock123 committed Aug 11, 2016
1 parent e9c4805 commit eec5d022660f112c369371a22d922badac9f8178
Showing with 14 additions and 1 deletion.
  1. +1 −1 lib/url.js
  2. +13 −0 test/parallel/test-url.js
View
@@ -619,7 +619,7 @@ Url.prototype.format = function() {
host = '';
}
search = search.replace('#', '%23');
search = search.replace(/#/g, '%23');
if (hash && hash.charCodeAt(0) !== 35/*#*/) hash = '#' + hash;
if (search && search.charCodeAt(0) !== 63/*?*/) search = '?' + search;
View
@@ -1165,6 +1165,19 @@ var formatTests = {
hash: '#frag',
search: '?abc=the#1?&foo=bar',
pathname: '/fooA100%mBr',
},
// multiple `#` in search
'http://example.com/?foo=bar%231%232%233&abc=%234%23%235#frag': {
href: 'http://example.com/?foo=bar%231%232%233&abc=%234%23%235#frag',
protocol: 'http:',
slashes: true,
host: 'example.com',
hostname: 'example.com',
hash: '#frag',
search: '?foo=bar#1#2#3&abc=#4##5',
query: {},
pathname: '/'
}
};
for (const u in formatTests) {

0 comments on commit eec5d02

Please sign in to comment.