-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
fix: encode permalink by default #3708
Conversation
I also notice an unusual behavior in tag/category name. It's automatically converted to ASCII when slugize as path, e.g. |
Can this be part of v4? Since this is a breaking change, if this PR misses v4, it would have to be in v5 😢 . |
I'm not sure If fully agree with this change. Because, the htmldncode should be done when ln you know that you are going to output this url into html, this at the end, in each plugin. A plugin could produce txt. And it would not be nice to ask to decode. |
That's a valid use case and a new I do, however, consider that as a minor use case. Majority of the Of course, my opinion could be uninformed. @theme-next is this a breaking change for theme? Note that existing plugin can remain backward compatible with v3 (if they wish) by using |
8ea4751
to
3d0ba3c
Compare
@@ -22,7 +23,7 @@ function urlForHelper(path = '/', options) { | |||
|
|||
// Resolve relative url | |||
if (options.relative) { | |||
return this.relative_url(this.path, path); | |||
return relative_url(this.path, path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this fix is already present in https://github.com/hexojs/hexo/pull/3710/files#diff-d89aa048c56f2709ea59155d3f91aa81 , I put this as not to depend #3710
* See also hexojs/hexo#3708
* See also hexojs/hexo#3708
What does it do?
While working on hexojs/hexo-generator-sitemap#68 and hexojs/hexo-generator-feed#93, I find it strange that plugins have to encode url themselves.
I believe url should be safe to consume by default. I can't think of any reason to use
this.url
in its original unescape form, except for aesthetic when displaying as a text, e.g. show http://foo.com/一二三 instead of http://foo.com/%E4%B8%80%E4%BA%8C%E4%B8%89Displaying a full link as text should be considered as an edge case. In that case, it should be up to the user to decode it (we could write a helper to help).
Do note link inside
href
is decoded when mouse-over.It's a breaking change because existing plugins need to remove url encode function, otherwise the percent symbol gets encoded (double-encoded), e.g.
foo%20bar
becomesfoo%25%20bar
.Note that existing plugin can remain backward compatible with v3 (if they wish) by using
encodeURI(decodeURI(str))
(instead of currentencodeURI(str)
, or useencodeURL()
of hexo-util.hexo-util is going to have
decodeURL()
which is an alternative to decodeURI with added ability to decode punycoded IDN.How to test
Pull request tasks