fix(python-sdk): port current JS stripAnsi regex to strip_ansi_escape_codes#1545
fix(python-sdk): port current JS stripAnsi regex to strip_ansi_escape_codes#1545mishushakov wants to merge 3 commits into
Conversation
…_codes The Python port still used the old ansi-regex pattern while the JS SDK was rewritten (#895) to match OSC sequences non-greedily up to the first string terminator and CSI sequences without requiring one. Aligns both implementations and mirrors the 14-case Python test suite into the JS SDK, which had no stripAnsi tests. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 2a058f7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
PR SummaryLow Risk Overview Both implementations now treat OSC, DCS, SOS, PM, and APC as string controls: non-greedy match from Adds a mirrored Vitest suite for Reviewed by Cursor Bugbot for commit 2a058f7. Bugbot is set up for automated code reviews on this repo. Configure here. |
Package ArtifactsBuilt from b81fc9c. Download artifacts from this workflow run. JS SDK ( npm install ./e2b-2.33.1-strip-ansi-python-sdk.0.tgzCLI ( npm install ./e2b-cli-2.13.3-strip-ansi-python-sdk.0.tgzPython SDK ( pip install ./e2b-2.32.0+strip.ansi.python.sdk-py3-none-any.whl |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f282d25cd8
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Addresses PR review feedback: the OSC-only branch regressed vs the old Python pattern, which stripped ST-terminated string controls like DCS (Sixel, tmux passthrough) through their terminator. Widen the branch to all ECMA-48 string controls (ESC ]/P/X/^/_ ... ST) in both the JS and Python implementations, keeping them byte-for-byte identical. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Python's \d matches any Unicode Nd digit by default, so malformed CSI sequences with e.g. Arabic-Indic digits were stripped in Python but kept by JS, whose \d is always ASCII-only. re.ASCII restores byte-for-byte parity; [\s\S] is unaffected. Addresses PR review. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Summary
The Python SDK's
strip_ansi_escape_codes(used to clean template build log messages) still used the old ansi-regex pattern, while the JS SDK'sstripAnsiwas rewritten in #895. This ports the current JS regex to Python so both SDKs clean logs identically: OSC sequences (hyperlinks, window titles) are matched non-greedily up to the first string terminator — including content spanning newlines — and CSI sequences are stripped without requiring a terminator.Following review feedback, both implementations now also strip the remaining ECMA-48 string controls — DCS (Sixel, tmux passthrough), SOS, PM, and APC — through their string terminator, so control payloads don't leak into cleaned logs. This goes beyond upstream
chalk/ansi-regex, click, and Rich, none of which fully strip DCS payloads, and restores what the old Python pattern handled.Also mirrors the Python test suite into the JS SDK (which previously had no
stripAnsitests) — 20 identical cases per side — and verified byte-for-byte identical output between the two implementations on all of them. Includes a patch changeset fore2band@e2b/python-sdk.Example
Log messages that previously leaked OSC or DCS sequences into template build output are now cleaned:
🤖 Generated with Claude Code