decodeURIComponent can throw at runtime
See original GitHub issueHello! First of all, thank for this module, I love it.
I was testing a route and I mistyped the url, for instance instead of write 2
I wrote "
, the result was that decodeURIComponent threw an URIError
exception at runtime!
I can easily fix this by using a try catch and return undefined
, but it will deoptimize the function.
We can also use a regex, something like:
if (/"/g.test(thisRoute)) return undefined
But actually I don’t know if "
is the only bad character!
Any suggestion? 😃
Thanks!
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (8 by maintainers)
Top Results From Across the Web
URIError: malformed URI sequence - MDN Web Docs - Mozilla
An URIError will be thrown if there is an attempt to encode a surrogate which is not part of a high-low pair, for...
Read more >encodeURIComponent throws an exception - Stack Overflow
I'd gladly do that if I could figure out which characters encodeURIComponent considers as valid. – K Mehta. Jun 1, 2013 at 2:48....
Read more >How to Throw Exceptions in Node.js - Rollbar
In this post, we'll take a look at what causes these errors in Node.js, and how to recover from them. What can cause...
Read more >Exception Handling - TypeScript Deep Dive - Gitbook
JavaScript has an Error class that you can use for exceptions. ... built-in error classes that inherit from Error that the JavaScript runtime...
Read more >JavaScript policy runtime error troubleshooting | Apigee Edge
The JavaScript policy can throw many different types of ScriptExecutionFailed errors. Some of the more commonly seen errors are listed in ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Looks like introducing try/catch doesn’t introduce a huge performance regression and solves the issue. Could you open a PR for this?
On Fri, Apr 28, 2017, 19:18 Tomas Della Vedova notifications@github.com wrote:
@davidmarkclements use
decodeURIComponent
andescape
together is not a good solution, since it introduces a wrong behaviour:Probably the best solution is to use a
try/catch
Here the benchmarks (in node
v6.10.0
) within and without thetry/catch
: