Skip to content

Commit

Permalink
fix(full_url_for): handle config.url with a trailing slash
Browse files Browse the repository at this point in the history
  • Loading branch information
curbengh committed Jul 1, 2020
1 parent 14fa817 commit 2917f4b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/full_url_for.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function fullUrlForHelper(path = '/') {
// Exit if input is an external link or a data url
if (data.hostname !== sitehost || data.origin === 'null') return path;

path = encodeURL(config.url + `/${path}`.replace(/\/{2,}/g, '/'));
path = encodeURL((config.url + `/${path}`).replace(/\/{2,}/g, '/'));
path = prettyUrls(path, prettyUrlsOptions);

return path;
Expand Down
6 changes: 6 additions & 0 deletions test/full_url_for.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ describe('full_url_for', () => {
fullUrlFor('/').should.eql(ctx.config.url + '/');
});

it('internal url - subdirectory with trailing slash', () => {
ctx.config.url = 'https://example.com/blog/';
fullUrlFor('index.html').should.eql(ctx.config.url + 'index.html');
fullUrlFor('/').should.eql(ctx.config.url);
});

it('internal url - no duplicate slash', () => {
ctx.config.url = 'https://example.com';
fullUrlFor('/index.html').should.eql('https://example.com/index.html');
Expand Down

0 comments on commit 2917f4b

Please sign in to comment.