Open xPaw opened 7 years ago
Okay my bad on this one, it throws the exception within URI
constructor, not withinString
, so it's the same issue as #352.
It's not the same as #352 as that was caused by an unfortunate change in URI.js v1.18.11 (and reverted in v1.19.0).
What is the exact input you're dealing with here?
You'll probably want to make sure that the new URI()
inside the withingString callback doesn't break for all the URLs in the string:
URI.withinString(text, function(uri) {
try {
var u = new URI(uri);
// …
} catch (error) {
// ignore the uri
return undefined;
}
});
@rodneyrehm FYI the workaround described above works but the type for withinString does not permit an undefined return value
but the type for withinString does not permit an undefined return value
@luisnaranjo733 what type? if you're referring to TypeScript you're looking for https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/urijs as this project is currently not providing type definitions itself.
Basically this function is not safe enough to be called on user input as it may crash with "URI malformed" which is thrown by nodejs' implementation of
decodeURIComponent
Right now the only suitable solution I see is wrapping it in a try/catch, which somewhat defeats the purpose of this function.
A link that throws:
http://a:%p@c