Skip to content

Commit 96cfa92

Browse files
imyllerMylesBorins
authored andcommittedOct 26, 2016
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 <[email protected]>
1 parent 3a3fde6 commit 96cfa92

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed
 

‎lib/url.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ Url.prototype.format = function() {
413413
pathname = pathname.replace(/[?#]/g, function(match) {
414414
return encodeURIComponent(match);
415415
});
416-
search = search.replace('#', '%23');
416+
search = search.replace(/#/g, '%23');
417417

418418
return protocol + host + pathname + search + hash;
419419
};

‎test/parallel/test-url.js

+13
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,19 @@ var formatTests = {
11271127
hash: '#frag',
11281128
search: '?abc=the#1?&foo=bar',
11291129
pathname: '/fooA100%mBr',
1130+
},
1131+
1132+
// multiple `#` in search
1133+
'http://example.com/?foo=bar%231%232%233&abc=%234%23%235#frag': {
1134+
href: 'http://example.com/?foo=bar%231%232%233&abc=%234%23%235#frag',
1135+
protocol: 'http:',
1136+
slashes: true,
1137+
host: 'example.com',
1138+
hostname: 'example.com',
1139+
hash: '#frag',
1140+
search: '?foo=bar#1#2#3&abc=#4##5',
1141+
query: {},
1142+
pathname: '/'
11301143
}
11311144
};
11321145
for (const u in formatTests) {

0 commit comments

Comments
 (0)
Please sign in to comment.