-
-
Notifications
You must be signed in to change notification settings - Fork 59
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
Leave IDN intact in permalink #116
Conversation
Maybe we should implement two |
I'm not sure there is a usage where IDN needs to be punycode encoded. |
lib/encode_url.js
Outdated
@@ -24,7 +24,8 @@ const encodeURL = (str) => { | |||
if (parsed.origin === 'null') return str; | |||
|
|||
parsed.search = encodeURI(safeDecodeURI(parsed.search)); | |||
return parsed.toString(); | |||
// preserve host (international domain name) as is. | |||
return format(parsed, { unicode: true}); |
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.
url.format() doesn't support port number in Node 8, see #114. This explains the failed test in Node 8.
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.
A workaround is to use punycode api
const { toUnicode } = require('./punycode');
return parsed.toString().replace(parsed.hostname, toUnicode(parsed.hostname));
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.
readme also needs to be updated.
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.
node 8 EOL is arround the corner, and will probably imply that this package, as well as many other and also hexo have a major version bump.
So this PR can wait a bit for another PR to drop node 8 compatibility
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.
we can use the workaround temporarily until node 8 EOL. I don't think this is a breaking change, I do agree IDN users would prefer not to punycode.
If this PR wait for hexo's major version bump, it would be many months away.
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.
Added the workaround. another change introduced by this PR is that IDN whether it's in unicode or punycoded is always encoded to unicode.
encodeURL(http://xn--br-mia.com/baz')
// http://bár.com/baz
When permalink is encoded by default, it breaks If a plugin wants to remain compatible with <v4, they can use If the IDN is not punycoded, But of course, as we learned from hexo-generator-feed & hexo-generator-sitemap, Note that I still +1 this PR. |
Because IDN only contain unicode, they do not need to be punycode encoded. (I bought one, I want the nice version, not the ugly one) See https://nodejs.org/docs/latest/api/url.html#url_url_format_url_options
Because IDN only contain unicode, they do not need to be punycode encoded.
(I bought one, I want the nice version, not the ugly one)
See https://nodejs.org/docs/latest/api/url.html#url_url_format_url_options