fix: treat special characters as literal in Search & Replace when reg…#254
Merged
spring1843 merged 3 commits intoDec 6, 2025
Merged
Conversation
…ex mode is off When regex mode is OFF, special replacement patterns like $&, $', $` were still being interpreted by JavaScript's String.replace(). This fix escapes $ characters in the replacement text to ensure they are treated literally. Fixes spring1843#183
✅ Deploy Preview for freedevtool ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where special replacement patterns (like $&, $', $\``) were being interpreted by JavaScript's String.replace()` even when regex mode was disabled in the Search & Replace tool. The fix ensures that dollar signs in replacement text are treated literally when not in regex mode.
Key Changes:
- Added conditional escaping of
$characters in replacement text when regex mode is off - Added two e2e tests to verify the fix handles both regular dollar signs and special replacement patterns correctly
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
client/src/pages/tools/search-replace.tsx |
Added conditional escaping logic to treat $ literally in replacement text when regex mode is disabled |
tests/e2e/tools/search-replace.spec.ts |
Added two e2e tests verifying that special characters and replacement patterns are treated literally when regex mode is off |
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.
Pull Request
📋 Description
When regex mode is OFF in the Search & Replace tool, special replacement patterns like
$&,$',$\`` were still being interpreted by JavaScript'sString.replace(). This fix escapes$` characters in the replacement text to ensure they are treated literally.🔧 Type of Change
📱 Screenshots/Videos
N/A
📝 Checklist
🔗 Related Issues
Fixes #183
📋 Additional Notes
Added two e2e tests to verify:
$100.00are treated literally in search/replace$&are treated as literal text, not as regex replacement patterns