diff --git a/index.js b/index.js index d45e67d..33b514a 100644 --- a/index.js +++ b/index.js @@ -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; diff --git a/test/stringify-url.js b/test/stringify-url.js index 2b3c372..9b6ff43 100644 --- a/test/stringify-url.js +++ b/test/stringify-url.js @@ -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 => {