Skip to content

Keep anchored replacements at string boundaries - #321

Merged
dgilland merged 1 commit into
dgilland:developfrom
yuefdev:fix/replacement-string-boundaries
Oct 18, 2026
Merged

dgilland merged 1 commit into
dgilland:developfrom
yuefdev:fix/replacement-string-boundaries

Conversation

@yuefdev

@yuefdev yuefdev commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

replace_start() and replace_end() promise string boundaries, but ^ and $ allow interior line boundaries with re.MULTILINE. $ also matches before a final newline without that flag, so replace_end("foo\n", "foo", "X") incorrectly returns "X\n".

Use the absolute string anchors \A and \Z. Regression cases cover literal suffixes, final newlines, compiled and inline multiline flags, both boundaries together and valid boundary matches.

Checks: three regressions fail before the fix; all 689 string tests and doctests pass afterwards. Ruff lint/format and git diff --check pass.

Prepared and verified with AI assistance (OpenCode, gpt-6.1-sol).

Signed-off-by: Yusuf Efe <120668197+yuefdev@users.noreply.github.com>
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 100.0%. remained the same — yuefdev:fix/replacement-string-boundaries into dgilland:develop

@dgilland
dgilland merged commit 04b837c into dgilland:develop Oct 18, 2026
12 checks passed
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.

3 participants