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

Is punycode.decode() a reasonable test for valid punycode FQDNs? #30

Closed
mikemaccana opened this issue Feb 27, 2015 · 6 comments
Closed

Comments

@mikemaccana
Copy link

I'm trying to check if a hostname string is a valid punycode/non-punycode FQDN. I can see that running:

 punycode.decode('☃')

Properly throws a RangeError which seems like it. But as this is a complex spec and I'm not sure after reading the docs: would punycode.decode() be considered a reasonable test of whether a string contains characters that would be invalid for punycode?

I'm aware of other restrictions on URLs, eg, string length.

@indolering
Copy link

Well decode is for converting Punycode ASCII labels into Unicode labels, so throwing any non-ASCII text into decode should throw an error. If you are starting with a string that may contain non-ASCII characters, run it through toASCII, which should throw an error if any characters are not allowed.

@mathiasbynens
Copy link
Owner

What @indolering said.

@indolering
Copy link

Having just figured out that domain name labels are supposed to be passed through Nameprep first, I think the answer to this question is "no" or at least "Don't use punycode.js to lint unicode DNS labels because it doesn't perform normalization."

@mikemaccana
Copy link
Author

Thanks @indolering! I kind of felt but couldn't turn into words what was wrong with the previous answer. My current understanding is that punicode only does punicode, i.e. it has no idea what a valid domain name is. I'll check out nameprep too!

@mikemaccana
Copy link
Author

I gather nameprep is this spec: https://en.wikipedia.org/wiki/Nameprep ?

@mathiasbynens
Copy link
Owner

@mikemaccana Correct.

mathiasbynens/todo#9 seems relevant.

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

No branches or pull requests

3 participants