Skip to content

Commit 1d24ce0

Browse files
committed
fix: Encode fragmentIdentifier with encodeURI method not encodeURIComponent at stringifyUrl
1 parent 5beef41 commit 1d24ce0

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,15 @@ function validateArrayFormatSeparator(value) {
222222

223223
function encode(value, options) {
224224
if (options.encode) {
225-
return options.strict ? strictUriEncode(value) : encodeURIComponent(value);
225+
if (options[encodeFragmentIdentifier]) {
226+
return encodeURI(value);
227+
}
228+
229+
if (options.strict) {
230+
return strictUriEncode(value);
231+
}
232+
233+
return encodeURIComponent(value);
226234
}
227235

228236
return value;

test/stringify-url.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ test('stringify URL with fragment identifier', t => {
2626
t.deepEqual(queryString.stringifyUrl({url: 'https://foo.bar/#abc', query: {}, fragmentIdentifier: 'top'}), 'https://foo.bar/#top');
2727
t.deepEqual(queryString.stringifyUrl({url: 'https://foo.bar', query: {}}), 'https://foo.bar');
2828
t.deepEqual(queryString.stringifyUrl({url: 'https://foo.bar', query: {}, fragmentIdentifier: 'foo bar'}), 'https://foo.bar#foo%20bar');
29+
t.deepEqual(queryString.stringifyUrl({url: 'https://foo.bar/', query: {}, fragmentIdentifier: '/foo/bar'}), 'https://foo.bar/#/foo/bar');
2930
});
3031

3132
test('skipEmptyString:: stringify URL with a query string', t => {

0 commit comments

Comments
 (0)