Skip to content

fix: treat special characters as literal in Search & Replace when reg…#254

Merged
spring1843 merged 3 commits into
spring1843:mainfrom
Hasham-dev:fix-search-replace-special-chars
Dec 6, 2025
Merged

fix: treat special characters as literal in Search & Replace when reg…#254
spring1843 merged 3 commits into
spring1843:mainfrom
Hasham-dev:fix-search-replace-special-chars

Conversation

@Hasham-dev

Copy link
Copy Markdown
Contributor

Pull Request

📋 Description

When regex mode is OFF in the Search & Replace tool, 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.

🔧 Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update
  • 🧹 Code refactoring (no functional changes)
  • ⚡ Performance improvement
  • 🧪 Test addition or modification
  • 🔧 Build/CI configuration change

📱 Screenshots/Videos

N/A

📝 Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code where necessary
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

🔗 Related Issues

Fixes #183

📋 Additional Notes

Added two e2e tests to verify:

  1. Special characters like $100.00 are treated literally in search/replace
  2. Special replacement patterns like $& are treated as literal text, not as regex replacement patterns

…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
@netlify

netlify Bot commented Dec 1, 2025

Copy link
Copy Markdown

Deploy Preview for freedevtool ready!

Name Link
🔨 Latest commit 2d86968
🔍 Latest deploy log https://app.netlify.com/projects/freedevtool/deploys/693397c862ef2400083de1b0
😎 Deploy Preview https://deploy-preview-254--freedevtool.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copilot AI 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.

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

@spring1843 spring1843 merged commit 02f32de into spring1843:main Dec 6, 2025
5 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.

[Bug]: When Regex mode is OFF, the tool should treat . * ? + as plain text.

3 participants