mathiasbynens / mathiasbynens/punycode.js
toUnicode fails for malformed input
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1.7k
- Forks
- 170
- PR merge metrics
- No merged PRs in 30d
Description
Hi there,
Thanks for developing and maintaining this package 🙇
Earlier today, I ran into a weird error when another script produced a malformed string which is not a punycode, but looks like one: "xn--http.com".
Per [RFC 3490](https://www.ietf.org/rfc/rfc3490.txt), `toUnicode` should never fail:
```
ToUnicode never fails. If any step fails, then the original input
sequence is returned immediately in that step.
```
Unfortunately, this is not always the case with `punycode.toUnicode`:
```
> punycode.toUnicode('xn--http')
RangeError: Invalid input
at error (punycode.js:42:8)
at decode (punycode.js:235:5)
at punycode.js:389:6
at map (punycode.js:57:20)
at mapDomain (punycode.js:84:18)
at Object.toUnicode (punycode.js:387:9)
```
It would be great if `punycode` silently ignored exceptions and returned the given input.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the failure with punycode.toUnicode('xn--http') and read the toUnicode, mapDomain, and decode paths in punycode.js. Done means malformed input returns the original input instead of raising RangeError, as required by the quoted RFC behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100