-
-
Notifications
You must be signed in to change notification settings - Fork 5k
fix(helpers, tag plugins): encode url by default #3710
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8edb005
fix(helpers, tag plugins): encode url by default
curbengh dcde0ae
test(helpers, tag plugins): encode url by default
curbengh d1da580
refactor: use url_for from hexo-util
curbengh 4624058
refactor: use relative_url from hexo-util
curbengh 249a433
style: remove unnecessary argument initialize
curbengh 1e61096
test(relative_url): should encode path
curbengh ec83d43
refactor: utilize url_for() helper to prepend config.root
curbengh f24a66c
refactor: replace Function.bind() with Function.call()
curbengh d7cd1f1
refactor: url_for path
curbengh 8f985eb
fix: function binding and module destructure
curbengh 55760f8
refactor(relative_url): 'this' binding is not required
curbengh ff38e12
fix: url_for() already encode path
curbengh 6aeab6f
refactor: initialize url_for() outside of exports
curbengh 382b0de
fix: use url.resolve() as a workaround for Windows compatibility
curbengh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,7 @@ | ||
'use strict'; | ||
|
||
function relativeUrlHelper(from = '', to = '') { | ||
const fromParts = from.split('/'); | ||
const toParts = to.split('/'); | ||
const length = Math.min(fromParts.length, toParts.length); | ||
let i = 0; | ||
const { relative_url } = require('hexo-util'); | ||
|
||
for (; i < length; i++) { | ||
if (fromParts[i] !== toParts[i]) break; | ||
} | ||
|
||
let out = toParts.slice(i); | ||
|
||
for (let j = fromParts.length - i - 1; j > 0; j--) { | ||
out.unshift('..'); | ||
} | ||
|
||
const outLength = out.length; | ||
|
||
// If the last 2 elements of `out` is empty strings, replace them with `index.html`. | ||
if (outLength > 1 && !out[outLength - 1] && !out[outLength - 2]) { | ||
out = out.slice(0, outLength - 2).concat('index.html'); | ||
} | ||
|
||
return out.join('/').replace(/\/{2,}/g, '/'); | ||
} | ||
|
||
module.exports = relativeUrlHelper; | ||
module.exports = function(from, to) { | ||
return relative_url(from, to); | ||
}; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,7 @@ | ||
'use strict'; | ||
|
||
const url = require('url'); | ||
const relative_url = require('./relative_url'); | ||
const { url_for } = require('hexo-util'); | ||
|
||
function urlForHelper(path = '/', options) { | ||
if (path[0] === '#' || path.startsWith('//')) { | ||
return path; | ||
} | ||
|
||
const { config } = this; | ||
const { root } = config; | ||
const data = url.parse(path); | ||
|
||
options = Object.assign({ | ||
relative: config.relative_link | ||
}, options); | ||
|
||
// Exit if this is an external path | ||
if (data.protocol) { | ||
return path; | ||
} | ||
|
||
// Resolve relative url | ||
if (options.relative) { | ||
return relative_url(this.path, path); | ||
} | ||
|
||
// Prepend root path | ||
path = root + path; | ||
|
||
return path.replace(/\/{2,}/g, '/'); | ||
} | ||
|
||
module.exports = urlForHelper; | ||
module.exports = function(path, options) { | ||
return url_for.call(this, path, options); | ||
}; | ||
curbengh marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.