mathiasbynens / mathiasbynens/punycode.js

toUnicode fails for malformed input

Open
#85 0 comments 5 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.