Skip to content

tests: use regex for ANSI escape code detection in has_ansi_escape_codes()#235

Open
adityamoolya wants to merge 1 commit intogruns:masterfrom
adityamoolya:fix/use-regex-for-ansi-escape-detection
Open

tests: use regex for ANSI escape code detection in has_ansi_escape_codes()#235
adityamoolya wants to merge 1 commit intogruns:masterfrom
adityamoolya:fix/use-regex-for-ansi-escape-detection

Conversation

@adityamoolya
Copy link
Copy Markdown

Implemented the TODO in tests/test_icecream.py:41 by replacing the oversimplified ANSI escape detection helper with regex-based detection.

Previously has_ansi_escape_codes() only checked for the substring \x1b[, which could produce false positives because it did not validate a complete ANSI CSI escape sequence.

This PR replaces that logic with a precompiled regex that matches full CSI sequences:

_ANSI_CSI_RE = re.compile(r'\x1b[[0-9;]*[A-Za-z]')

Changes included:

  • Added import re
  • Added compiled _ANSI_CSI_RE
  • Updated has_ansi_escape_codes() to use regex matching
  • Removed resolved TODO(grun) comment

Testing

All existing tests that depend on has_ansi_escape_codes() (test_coloring, test_non_ascii_characters_no_syntax_highlighting, test_no_color_* suite) continue to pass with no modifications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant