-
-
Notifications
You must be signed in to change notification settings - Fork 36.7k
util: fix OSC 8 hyperlink stripping in stripVTControlCharacters #64319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nodejs-github-bot
merged 6 commits into
nodejs:main
from
dushyant-hada-90:fix/strip-vt-osc-8-uri-chars
Aug 24, 2026
+27
−7
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0817b0a
util: fix OSC 8 hyperlink stripping in stripVTControlCharacters
dushyant-hada-90 273fbfe
util: use [;:] as CSI parameter separator, matching ansi-regex v6.2.0
dushyant-hada-90 29f6205
util: extend stripVTControlCharacters regression tests
dushyant-hada-90 20fc79d
util: use full ansi-regex commit SHA in comment
dushyant-hada-90 983f681
util: align CSI regex grouping with ansi-regex
dushyant-hada-90 8bcabf1
test: clarify unterminated OSC strip comment
dushyant-hada-90 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -282,16 +282,14 @@ const meta = [ | |
| ]; | ||
|
|
||
| // Regex used for ansi escape code splitting | ||
| // Ref: https://github.com/chalk/ansi-regex/blob/f338e1814144efb950276aac84135ff86b72dc8e/index.js | ||
| // Ref: https://github.com/chalk/ansi-regex/blob/72bc570aaf25fca25541b49c6a8564f3ec63e835/index.js | ||
| // License: MIT by Sindre Sorhus <[email protected]> | ||
| // Matches all ansi escape code sequences in a string | ||
| const ansi = new RegExp( | ||
| '[\\u001B\\u009B][[\\]()#;?]*' + | ||
| '(?:(?:(?:(?:;[-a-zA-Z\\d\\/\\#&.:=?%@~_]+)*' + | ||
| '|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/\\#&.:=?%@~_]*)*)?' + | ||
| '(?:\\u0007|\\u001B\\u005C|\\u009C))' + | ||
| '|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?' + | ||
| '[\\dA-PR-TZcf-nq-uy=><~]))', 'g', | ||
| '(?:\\u001B\\][\\s\\S]*?(?:\\u0007|\\u001B\\u005C|\\u009C))' + | ||
| '|[\\u001B\\u009B][[\\]()#;?]*' + | ||
| '(?:\\d{1,4}(?:[;:]\\d{0,4})*)?' + | ||
| '[\\dA-PR-TZcf-nq-uy=><~]', 'g', | ||
| ); | ||
|
|
||
| let getStringWidth; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,9 +18,31 @@ for (const ST of ['\u0007', '\u001B\u005C', '\u009C']) { | |
| tests.push( | ||
| [`\u001B]8;;mailto:[email protected]${ST}mail\u001B]8;;${ST}`, 'mail'], | ||
| [`\u001B]8;k=v;https://example-a.com/?a_b=1&c=2#tit%20le${ST}click\u001B]8;;${ST}`, 'click'], | ||
| [`\u001B]8;;https://example.com/(foo${ST}label\u001B]8;;${ST}`, 'label'], | ||
| [`\u001B]8;;https://example.com/foo)bar${ST}label\u001B]8;;${ST}`, 'label'], | ||
| [`\u001B]8;;https://example.com/!foo${ST}label\u001B]8;;${ST}`, 'label'], | ||
| [`\u001B]8;;https://example.com/foo+bar${ST}label\u001B]8;;${ST}`, 'label'], | ||
| [`\u001B]8;;https://example.com/[foo]${ST}label\u001B]8;;${ST}`, 'label'], | ||
| [`\u001B]8;;https://example.com/foo$bar${ST}label\u001B]8;;${ST}`, 'label'], | ||
| [`\u001B]8;;https://example.com/foo'bar${ST}label\u001B]8;;${ST}`, 'label'], | ||
| [`\u001B]8;;https://example.com/foo*bar${ST}label\u001B]8;;${ST}`, 'label'], | ||
| [`\u001B]8;;https://example.com/foo,bar${ST}label\u001B]8;;${ST}`, 'label'], | ||
| ); | ||
| } | ||
|
|
||
| // Colon-delimited CSI sub-parameters (SGR) should be stripped like the | ||
| // semicolon-delimited form. | ||
| tests.push( | ||
| ['\u001B[38:2:255:0:0mHello\u001B[0m', 'Hello'], | ||
| ['\u001B[4:3mUnderline\u001B[4:0m', 'Underline'], | ||
| ); | ||
|
|
||
| // Unterminated OSC does not match the OSC alternative; the CSI alternative may | ||
| // still consume a short prefix (here ESC ] 8 ;; h), leaving the remainder. | ||
| tests.push( | ||
| ['\u001B]8;;https://example.com/no-terminator', 'ttps://example.com/no-terminator'], | ||
| ); | ||
|
|
||
| test('util.stripVTControlCharacters', (t) => { | ||
| for (const [before, expected] of tests) { | ||
| t.assert.strictEqual(util.stripVTControlCharacters(before), expected); | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.