chalk / ansi-regex

Regular expression for matching ANSI escape codes
MIT License
184 stars 79 forks source link

Unable to match links ended with `\u001B` rather than `\u0007`. #56

Closed RedYetiDev closed 1 month ago

RedYetiDev commented 3 months ago

ansi-regex cannot match link regexes that end in \u0001B, as the regex only allows \u0007.

Example: \x1b]8;;http://example.com/\x1b\\This is a link\x1b]8;;\x1b\\ hello Reference: https://github.com/nodejs/node/issues/53697

hildjj commented 3 months ago

For anyone digging into this, "OSC" is an "Operating System Command". One reference I've found is from Microsoft, which claims:

As OSC sequences, they are ended with a String Terminator represented as and transmitted with ESC \ (0x1B 0x5C). BEL (0x7) may be used instead as the terminator, but the longer form is preferred.

So the bug should probably read "cannot match link regexes that end in \u0001B\u005c".

I've verified that iTerm2 at least does accept the sample string, so this isn't just a Microsoft thing.

llimllib commented 1 month ago

wiki says that 0x9C and 0x1B 0x5C (ESC ) are both standard STs and should be supported; I wish there were a real spec but it seems like practice is all we have here.

The OSC8 spec uses 0x1B 0x5C, for whatever that's worth.