Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: utilize legacy url.parse() in url_for() & full_url_for() #125

Merged
merged 4 commits into from
Nov 10, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/full_url_for.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const { parse, URL } = require('url');
const encodeURL = require('./encode_url');
const isExternalLink = require('./is_external_link');

function fullUrlForHelper(path = '/') {
if (path.startsWith('//')) return path;
Expand All @@ -12,7 +11,7 @@ function fullUrlForHelper(path = '/') {
const data = new URL(path, `http://${sitehost}`);

// Exit if this is an external link
if (isExternalLink.call(this, path)) return path;
if (data.origin !== 'null' && data.hostname !== sitehost) return path;

path = encodeURL(config.url + `/${path}`.replace(/\/{2,}/g, '/'));
return path;
Expand Down
3 changes: 1 addition & 2 deletions lib/url_for.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const { parse, URL } = require('url');
const encodeURL = require('./encode_url');
const isExternalLink = require('./is_external_link');
const relative_url = require('./relative_url');

function urlForHelper(path = '/', options) {
Expand All @@ -16,7 +15,7 @@ function urlForHelper(path = '/', options) {
const data = new URL(path, `http://${sitehost}`);

// Exit if this is an external link
if (isExternalLink.call(this, path)) return path;
if (data.origin !== 'null' && data.hostname !== sitehost) return path;
curbengh marked this conversation as resolved.
Show resolved Hide resolved

options = Object.assign({
relative: config.relative_link
Expand Down
5 changes: 1 addition & 4 deletions test/full_url_for.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
describe('full_url_for', () => {
const ctx = {
config: {
url: 'http://example.com',
external_link: {
exclude: []
}
url: 'http://example.com'
}
};

Expand Down
5 changes: 1 addition & 4 deletions test/url_for.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
describe('url_for', () => {
const ctx = {
config: {
url: 'http://example.com',
external_link: {
exclude: []
}
url: 'http://example.com'
}
};

Expand Down