Skip to content

feat(url_for): convert backward to forward slash - #228

Open
curbengh wants to merge 1 commit into
hexojs:masterfrom
curbengh:url_for-backslash
Open

feat(url_for): convert backward to forward slash#228
curbengh wants to merge 1 commit into
hexojs:masterfrom
curbengh:url_for-backslash

Conversation

@curbengh

@curbengh curbengh commented Aug 15, 2020

Copy link
Copy Markdown
Contributor

to deal with Windows path, see https://github.com/hexojs/hexo/pull/4479/files#r470968350

url_for() deals with relative URLs, which should never have backward slash.

full_url_for() doesn't need to update because encodeURL() already have conversion in place (via URL API).

I'm assuming no one uses backward slash "%5C" in urls.

@curbengh

curbengh commented Aug 15, 2020

Copy link
Copy Markdown
Contributor Author

Alternatively, we could also convert in encodeURL() instead (used by both url_for() and full_url_for().


doesn't work quite well in encodeURL(), e.g. url_for('\\foo\\bar').

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 97.424% when pulling 7f97f79 on curbengh:url_for-backslash into b34456a on hexojs:master.

@SukkaW

SukkaW commented Aug 15, 2020

Copy link
Copy Markdown
Member

url_for is designed to transform the URL path. It should not be used to convert file system path into URL.

@curbengh

curbengh commented Aug 16, 2020

Copy link
Copy Markdown
Contributor Author

full_url_for() currently converts slash (via URL API) whereas url_for() percent-encode it, this PR makes them behave similarly.

const { format } = require('url');

const lorem = new URL('http://ipsum.com/foo\\bar/baz\\dolor')

console.log(format(lorem))
// http://ipsum.com/foo/bar/baz/dolor

@curbengh
curbengh marked this pull request as ready for review August 17, 2020 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants