Skip to content

Commit

Permalink
Revert "fix: handle unexpected config.url (#204)" (#208)
Browse files Browse the repository at this point in the history
This reverts commit 358893b.
  • Loading branch information
SukkaW committed May 18, 2020
1 parent 358893b commit 7b2f2a7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 33 deletions.
14 changes: 5 additions & 9 deletions lib/full_url_for.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@ function fullUrlForHelper(path = '/') {
return cache.apply(`${config.url}-${prettyUrlsOptions.trailing_index}-${prettyUrlsOptions.trailing_html}-${path}`, () => {
if (/^(\/\/|http(s)?:)/.test(path)) return path;

const config_url = config.url ? config.url : '';
const sitehost = parse(config.url).hostname || config.url;
const data = new URL(path, `http://${sitehost}`);

// if sitehost is empty, skip this step
if (config_url !== '' && config_url !== null) {
const sitehost = parse(config_url).hostname || config.url;
const data = new URL(path, `http://${sitehost}`);
// Exit if input is an external link or a data url
if (data.hostname !== sitehost || data.origin === 'null') return 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
24 changes: 0 additions & 24 deletions test/full_url_for.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,28 +88,4 @@ describe('full_url_for', () => {
fullUrlFor(url).should.eql(url);
});
});

it('config url is empty', () => {
ctx.config.url = '';
fullUrlFor('test/').should.eql('/test/');
fullUrlFor('https://hexo.io/').should.eql('https://hexo.io/');
fullUrlFor('/foo/bar.html').should.eql('/foo/bar');
fullUrlFor('#test').should.eql('/#test');
});

it('config url is null', () => {
ctx.config.url = null;
fullUrlFor('test/').should.eql('/test/');
fullUrlFor('https://hexo.io/').should.eql('https://hexo.io/');
fullUrlFor('/foo/bar.html').should.eql('/foo/bar');
fullUrlFor('#test').should.eql('/#test');
});

it('config url is undefined', () => {
delete ctx.config.url;
fullUrlFor('test/').should.eql('/test/');
fullUrlFor('https://hexo.io/').should.eql('https://hexo.io/');
fullUrlFor('/foo/bar.html').should.eql('/foo/bar');
fullUrlFor('#test').should.eql('/#test');
});
});

0 comments on commit 7b2f2a7

Please sign in to comment.