Skip to content

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

Draft
adityamoolya wants to merge 1 commit into
gruns:masterfrom
adityamoolya:fix/use-regex-for-ansi-escape-detection
Draft

adityamoolya wants to merge 1 commit into
gruns: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.

@Jakeroid

Copy link
Copy Markdown
Collaborator

@adityamoolya Thank you!

I see there is currently a merge conflict with the main branch. Would you like to resolve it?

@adityamoolya
adityamoolya force-pushed the fix/use-regex-for-ansi-escape-detection branch from fe34fbe to a891ba3 Compare August 21, 2026 06:54
@adityamoolya

Copy link
Copy Markdown
Author

@adityamoolya Thank you!

I see there is currently a merge conflict with the main branch. Would you like to resolve it?

Resolved the merge conflict and force-pushed the update. The PR should now merge cleanly.

@adityamoolya
adityamoolya marked this pull request as draft October 2, 2026 16:40
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.

2 participants