linkifyjs
linkifyjs copied to clipboard
Url detected by the library but considered as invalid by URL native module
I use the library to detect, in messages, URLs used to scam people. However, today, the detection failed on a message due to an invalid library detection preventing a parse by nodejs' native URL library
Code
function findURLs(text: string): URL[] {
return linkify.find(text, "url")
.map( l => new URL(l.href) );
}
const messageWithTwoUrls = "[https://store.steampowered.com](https://u.com/aig)"
const res = findURLs(messageWithTwoUrls) // <- error thrown by new URL
Url detected
[{
"type": "url",
"value": "https://store.steampowered.com](https://u.com/aig)",
"isLink": true,
"href": "https://store.steampowered.com](https://u.com/aig)"
}]
Expected
[{
"type": "url",
"value": "https://store.steampowered.com",
"isLink": true,
"href": "https://store.steampowered.com"
},{
"type": "url",
"value": "https://u.com/aig",
"isLink": true,
"href": "https://u.com/aig"
}]