anser
anser copied to clipboard
Linkify breaks with URLs surrounded by color codes
If you have a URL that's got color codes around it and linkify
the output, you'll get a </span>
in the link because the regex for URL (specifically the host/path portion) will match any non-whitespace character: https://github.com/IonicaBizau/anser/blob/fb58237c4c6f9c24e1fc5e985b7d50903cacd820/lib/index.js#L196-L198
Example
(Same code, just inlined here)
var anser = require("anser")
const link = anser.linkify(anser.ansiToHtml(
"\u001b[31mhttps://github.com/IonicaBizau/anser\u001b[0m"
))
console.log(link)
RunKit repro (same code as here): https://runkit.com/milas/605a270caf5fed001a4b6e93
Output
<span style="color:rgb(187, 0, 0)"><a href="https://github.com/IonicaBizau/anser</span>">https://github.com/IonicaBizau/anser</span></a>
Solution
If we assume the input has been escaped with escapeForHtml
, perhaps linkify
's regex could be made more strict to only match on URL safe characters? Just adding <
to the not matching set would also probably be sufficient for this case, but there might be other edge cases re: linkifying in general (i.e. not induced by having a surrounding color code) that are still missed.
Hmm, good catch! I will happily merge a PR fixing this! ❇️
any plan to fix this?