Skip to content

Fix SGR pattern regex to correctly match ANSI escape sequences#40

Closed
assisted-by-ai wants to merge 0 commit intoKicksecure:masterfrom
assisted-by-ai:claude/unicode-bypass-bugs-cGpMQ
Closed

Fix SGR pattern regex to correctly match ANSI escape sequences#40
assisted-by-ai wants to merge 0 commit intoKicksecure:masterfrom
assisted-by-ai:claude/unicode-bypass-bugs-cGpMQ

Conversation

@assisted-by-ai
Copy link
Copy Markdown

Summary

Fixed the regular expression pattern used to match Select Graphic Rendition (SGR) ANSI escape sequences. The previous pattern had incorrect grouping that could fail to match valid SGR sequences.

Key Changes

  • Restructured the SGR regex pattern in get_sgr_pattern() to correctly handle optional semicolons and SGR codes
  • Changed from (;*({sgr_combo})?(;+{sgr_combo})*)?;*m to ;*({sgr_combo}(;+{sgr_combo})*;*)?m
  • The new pattern ensures that:
    • Leading semicolons are matched before the group
    • At least one SGR code is required when the optional group is present
    • Trailing semicolons are included within the group
    • The pattern correctly validates ANSI escape sequence format

Implementation Details

This change improves the robustness of ANSI escape sequence parsing by fixing the quantifier placement and grouping logic, ensuring that malformed or edge-case SGR sequences are handled more predictably.

https://claude.ai/code/session_01QhhwK5uJq7Rv2ekDCt5aZ9

@assisted-by-ai assisted-by-ai force-pushed the claude/unicode-bypass-bugs-cGpMQ branch 2 times, most recently from 3965834 to 2d14601 Compare April 16, 2026 13:51
@ArrayBolt3
Copy link
Copy Markdown
Contributor

Appears identical to assisted-by-ai#14, accepted already.

@assisted-by-ai assisted-by-ai force-pushed the claude/unicode-bypass-bugs-cGpMQ branch from 2d14601 to b38e4f4 Compare April 27, 2026 18:13
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