Repository navigation
FIX: validate pattern, replacement choices, and flags in SearchReplaceConverter - #3152
Merged
Roman Lutz (romanlutz) merged 3 commits intoOct 13, 2026
Conversation
Roman Lutz (romanlutz)
requested changes
Oct 13, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: a42d9bc0-29f5-4def-8991-0d02f510f1f7
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: a42d9bc0-29f5-4def-8991-0d02f510f1f7
Roman Lutz (romanlutz)
approved these changes
Oct 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Validate
SearchReplaceConverterconfiguration during construction instead of waiting for conversion to fail. Include regex flags in the converter's identifier so configurations with different matching behavior have different identities.Changes
regex_flagsduring initialization. Invalid regex syntax raises a descriptiveValueError.""with"-"in"ab"still produces"-a-b-".replaceto be a string or a non-empty list of strings. Copy replacement lists so later caller changes do not affect the converter.main.Previously, an empty replacement list failed at runtime with
IndexError, and invalid replacement types or regex patterns failed during substitution. These invalid configurations now fail during initialization. Empty replacement strings remain supported.Tests and Documentation
Added tests for invalid patterns, replacement choices, flag types, flag-aware execution, identifiers, and empty replacements. Added four regression cases for valid empty patterns, covering non-empty and empty prompts, an empty replacement, and a replacement list. All four regression cases failed before the compatibility fix and pass afterward.
Updated the constructor docstring to document empty-pattern support and validation errors.
Validation on Windows with Python 3.14.4, after merging
main:Targeted tests: 606 passed, 6 skipped.
Ruff lint: passed.
Ruff formatting: passed; both files already formatted.
Type checking: passed.
The full test suite and other OS/Python combinations were not run locally.
JupyText was not run because this change does not modify notebooks or notebook examples.