Skip to content

Commit

Permalink
Merge 4ed1ba8 into e02a3aa
Browse files Browse the repository at this point in the history
  • Loading branch information
bitshadow committed Dec 18, 2018
2 parents e02a3aa + 4ed1ba8 commit 72717f7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -133,7 +133,7 @@ module.exports = (urlString, options) => {
urlString = urlObj.toString();

// Remove ending `/`
if (options.removeTrailingSlash || urlObj.pathname === '/') {
if ((options.removeTrailingSlash || urlObj.pathname === '/') && urlObj.hash === '') {
urlString = urlString.replace(/\/$/, '');
}

Expand Down
3 changes: 3 additions & 0 deletions test.js
Expand Up @@ -115,6 +115,7 @@ test('removeTrailingSlash option', t => {
t.is(normalizeUrl('http://sindresorhus.com/', options), 'http://sindresorhus.com');
t.is(normalizeUrl('http://sindresorhus.com/redirect/'), 'http://sindresorhus.com/redirect');
t.is(normalizeUrl('http://sindresorhus.com/redirect/', options), 'http://sindresorhus.com/redirect/');
t.is(normalizeUrl('http://sindresorhus.com/#/', options), 'http://sindresorhus.com/#/');
});

test('removeDirectoryIndex option', t => {
Expand Down Expand Up @@ -151,13 +152,15 @@ test('removeTrailingSlash and removeDirectoryIndex options)', t => {
};
t.is(normalizeUrl('http://sindresorhus.com/path/', options1), 'http://sindresorhus.com/path');
t.is(normalizeUrl('http://sindresorhus.com/path/index.html', options1), 'http://sindresorhus.com/path');
t.is(normalizeUrl('http://sindresorhus.com/#/path/', options1), 'http://sindresorhus.com/#/path/');

const options2 = {
removeTrailingSlash: false,
removeDirectoryIndex: true
};
t.is(normalizeUrl('http://sindresorhus.com/path/', options2), 'http://sindresorhus.com/path/');
t.is(normalizeUrl('http://sindresorhus.com/path/index.html', options2), 'http://sindresorhus.com/path/');
t.is(normalizeUrl('http://sindresorhus.com/#/path/', options2), 'http://sindresorhus.com/#/path/');
});

test('sortQueryParameters option', t => {
Expand Down

0 comments on commit 72717f7

Please sign in to comment.