Skip to content

fix: avoid mid-word splits in text_transforms.replace#6439

Merged
longcw merged 1 commit into
mainfrom
longc/text-transform-replace-streaming
Jul 17, 2026
Merged

fix: avoid mid-word splits in text_transforms.replace#6439
longcw merged 1 commit into
mainfrom
longc/text-transform-replace-streaming

Conversation

@longcw

@longcw longcw commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

replace held back a fixed max(len(key)) - 1 trailing characters on every chunk to catch keys split across streaming boundaries, so ordinary words were emitted split mid-word (e.g. "connect." arrived as "conne" + "ct.").

It now buffers only a trailing run that could still start a replacement key and forwards the rest immediately. Substitution uses a single compiled alternation, which also avoids cascading replacements and prefers the longest match on overlapping keys.

`replace` held back a fixed `max(len(key)) - 1` trailing characters on every chunk to catch keys split across streaming boundaries, so ordinary words were emitted split mid-word (e.g. "connect." arrived as "conne" + "ct.").

It now buffers only a trailing run that could still start a replacement key and forwards the rest immediately. Substitution uses a single compiled alternation, which also avoids cascading replacements and prefers the longest match on overlapping keys.
@longcw
longcw requested a review from a team as a code owner July 15, 2026 12:32

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

@theomonnom theomonnom left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow nice catch

@longcw
longcw merged commit 845fc28 into main Jul 17, 2026
26 checks passed
@longcw
longcw deleted the longc/text-transform-replace-streaming branch July 17, 2026 05:23
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