Skip to content

Commit bfeb74c

Browse files
committed
fix: prevent strip_codes from matching across OSC 8 sequences
Changes the OSC sequence regex from .*? to [^\x1b]* to prevent matching across escape sequence boundaries. This fixes a bug where text between OSC 8 hyperlinks was incorrectly stripped in terminals with proper OSC 8 support (e.g., Ghostty). The new pattern stops at the first escape sequence terminator rather than potentially continuing to a later one, preventing over-matching. Fixes two failing tests: - test_strip_codes_preserves_text_between_osc8_hyperlinks - test_strip_codes_with_ui_link
1 parent ac0f707 commit bfeb74c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/cli/ui/ansi.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ def printing_width(str)
4242
#
4343
#: (String str) -> String
4444
def strip_codes(str)
45-
str.gsub(/\x1b\[[\d;]+[A-Za-z]|\x1b\][\d;]+.*?\x1b\\|\r/, '')
45+
# Strip SGR (color) codes, OSC sequences (including hyperlinks), and carriage returns
46+
# Use [^\x1b]* instead of .*? to prevent matching across escape sequences
47+
str.gsub(/\x1b\[[\d;]+[A-Za-z]|\x1b\][\d;]+[^\x1b]*\x1b\\|\r/, '')
4648
end
4749

4850
# Returns an ANSI control sequence

0 commit comments

Comments
 (0)