Skip to content
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

Merged
merged 4 commits into from Nov 3, 2019

Conversation

@tomap
Copy link
Contributor

tomap commented Oct 27, 2019

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

@coveralls

This comment has been minimized.

Copy link

coveralls commented Oct 27, 2019

Coverage Status

Coverage increased (+0.007%) to 95.432% when pulling e14f8e0 on tomap:IDNUnicode into 4f07d2b on hexojs:master.

@SukkaW SukkaW requested a review from curbengh Oct 27, 2019
@SukkaW

This comment has been minimized.

Copy link
Member

SukkaW commented Oct 27, 2019

Maybe we should implement two encode_url() method for different usages.

@tomap

This comment has been minimized.

Copy link
Contributor Author

tomap commented Oct 27, 2019

I'm not sure there is a usage where IDN needs to be punycode encoded.

@@ -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});

This comment has been minimized.

Copy link
@curbengh

curbengh Oct 28, 2019

Contributor

url.format() doesn't support port number in Node 8, see #114. This explains the failed test in Node 8.

This comment has been minimized.

Copy link
@curbengh

curbengh Oct 28, 2019

Contributor

A workaround is to use punycode api

const { toUnicode } = require('./punycode');
return parsed.toString().replace(parsed.hostname, toUnicode(parsed.hostname));

This comment has been minimized.

Copy link
@curbengh

curbengh Oct 28, 2019

Contributor

readme also needs to be updated.

This comment has been minimized.

Copy link
@tomap

tomap Oct 28, 2019

Author Contributor

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

This comment has been minimized.

Copy link
@curbengh

curbengh Nov 2, 2019

Contributor

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.

This comment has been minimized.

Copy link
@curbengh

curbengh Nov 2, 2019

Contributor

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
@curbengh

This comment has been minimized.

Copy link
Contributor

curbengh commented Oct 28, 2019

I'm not sure there is a usage where IDN needs to be punycode encoded.

When permalink is encoded by default, it breaks encodeURI() (permalink is encoded twice).

If a plugin wants to remain compatible with <v4, they can use encodeURI(decodeURI()) or encodeURL() instead.

If the IDN is not punycoded, encodeURI(decodeURI()) will percent-encode the domain.

But of course, as we learned from hexo-generator-feed & hexo-generator-sitemap, encodeURI()/encodeURI(decodeURI()) should be avoided and use encodeURL() instead.

Note that I still +1 this PR.

@curbengh curbengh requested a review from hexojs/core Nov 2, 2019
tomap and others added 4 commits Oct 27, 2019
@curbengh curbengh dismissed stale reviews from SukkaW and themself via e14f8e0 Nov 2, 2019
@curbengh curbengh force-pushed the tomap:IDNUnicode branch from 7afde05 to e14f8e0 Nov 2, 2019
@curbengh curbengh requested a review from SukkaW Nov 2, 2019
@curbengh curbengh mentioned this pull request Nov 2, 2019
@SukkaW
SukkaW approved these changes Nov 2, 2019
@curbengh curbengh merged commit 8ebe0eb into hexojs:master Nov 3, 2019
3 checks passed
3 checks passed
Travis CI - Pull Request Build Passed
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
coverage/coveralls Coverage increased (+0.007%) to 95.432%
Details
@curbengh curbengh mentioned this pull request Nov 4, 2019
2 of 2 tasks complete
@curbengh curbengh added this to In progress in Drop legacy URL API via automation Nov 5, 2019
@SukkaW SukkaW moved this from In progress to Done in Drop legacy URL API Nov 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
4 participants
You can’t perform that action at this time.