Skip to content

Commit

Permalink
fix: Encode fragmentIdentifier with encodeURI method not encodeURICom…
Browse files Browse the repository at this point in the history
…ponent at stringifyUrl
  • Loading branch information
hanbin9775 committed Dec 4, 2022
1 parent 5beef41 commit 1d24ce0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion index.js
Expand Up @@ -222,7 +222,15 @@ function validateArrayFormatSeparator(value) {

function encode(value, options) {
if (options.encode) {
return options.strict ? strictUriEncode(value) : encodeURIComponent(value);
if (options[encodeFragmentIdentifier]) {
return encodeURI(value);
}

if (options.strict) {
return strictUriEncode(value);
}

return encodeURIComponent(value);
}

return value;
Expand Down
1 change: 1 addition & 0 deletions test/stringify-url.js
Expand Up @@ -26,6 +26,7 @@ test('stringify URL with fragment identifier', t => {
t.deepEqual(queryString.stringifyUrl({url: 'https://foo.bar/#abc', query: {}, fragmentIdentifier: 'top'}), 'https://foo.bar/#top');
t.deepEqual(queryString.stringifyUrl({url: 'https://foo.bar', query: {}}), 'https://foo.bar');
t.deepEqual(queryString.stringifyUrl({url: 'https://foo.bar', query: {}, fragmentIdentifier: 'foo bar'}), 'https://foo.bar#foo%20bar');
t.deepEqual(queryString.stringifyUrl({url: 'https://foo.bar/', query: {}, fragmentIdentifier: '/foo/bar'}), 'https://foo.bar/#/foo/bar');
});

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

0 comments on commit 1d24ce0

Please sign in to comment.