hexo-util icon indicating copy to clipboard operation
hexo-util copied to clipboard

feat(url_for): convert backward to forward slash

Open curbengh opened this issue 3 years ago • 4 comments

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 avatar Aug 15 '20 11:08 curbengh

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').

curbengh avatar Aug 15 '20 12:08 curbengh

Coverage Status

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

coveralls avatar Aug 15 '20 12:08 coveralls

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

SukkaW avatar Aug 15 '20 16:08 SukkaW

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 avatar Aug 16 '20 00:08 curbengh