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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

URL punycode differs from nodejs / chrome behaviour #1223

Open
amardeep opened this issue Mar 17, 2023 · 4 comments
Open

URL punycode differs from nodejs / chrome behaviour #1223

amardeep opened this issue Mar 17, 2023 · 4 comments

Comments

@amardeep
Copy link

Consider the following url which has non-ascii characters: https://饾殟饾殥饾殰饾殞饾殬饾殯饾殟.gg

While trying to parse this for the hostname, both nodejs and chrome return ascii string discord.gg but corejs returns xn--ci2hbbs5ase.gg

Here is the code:

import configurator from 'core-js-pure/configurator.js';

configurator({
    // By default polyfills are not used if they are available natively.
    usePolyfill: ['URL'], // Override that behaviour for URL.
});

import URL from 'core-js-pure/web/url.js'; // For URL

const url = new URL('https://饾殟饾殥饾殰饾殞饾殬饾殯饾殟.gg');
console.log(url.hostname); 
@zloirock
Copy link
Owner

zloirock commented Mar 17, 2023

Yes, I can confirm it. core-js URL punycode logic is not perfect (and I'm not sure that a complete acceptable fix for that is possible).

I can work on this issue only after some days, so if someone wanna work on it before - feel free.

@tasawar-hussain
Copy link

@zloirock It looks interesting, I can start looking into it, if you haven't already

@zloirock
Copy link
Owner

@tasawar-hussain 馃憤

@ehoogeveen-medweb
Copy link

I don't know if it would be useful (as it is written in C++), but Node.js recently switched to ada for URL parsing, and this uses idna for converting between unicode and ascii.

Maybe some inspiration could be taken from their utf32_to_punycode implementation, which seems relatively short and free of dependencies (though obviously JS doesn't start from UTF32).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants