hexo-util
hexo-util copied to clipboard
feat(url_for): convert backward to forward slash
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.
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')
.
Coverage remained the same at 97.424% when pulling 7f97f7945668781be630d2ccdfc1d26795ad25b4 on curbengh:url_for-backslash into b34456a7a56ae905c13a3541272176ef520a0488 on hexojs:master.
url_for
is designed to transform the URL path. It should not be used to convert file system path into URL.
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