Skip to content

Commit cc232cb

Browse files
committed
Fix passing empty fragmentIdentifier to stringifyUrl()
Fixes #380
1 parent 50271f2 commit cc232cb

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

base.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ export function stringifyUrl(object, options) {
489489
}
490490

491491
let hash = getHash(object.url);
492-
if (object.fragmentIdentifier) {
492+
if (typeof object.fragmentIdentifier === 'string') {
493493
const urlObjectForFragmentEncode = new URL(url);
494494
urlObjectForFragmentEncode.hash = object.fragmentIdentifier;
495495
hash = options[encodeFragmentIdentifier] ? urlObjectForFragmentEncode.hash : `#${object.fragmentIdentifier}`;

test/stringify-url.js

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

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

0 commit comments

Comments
 (0)