notepad-plus-plus / notepad-plus-plus/notepad-plus-plus
[BUG] "Replace with" also uses regex together with "Find what" in regex mode
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 29.4k
- Forks
- 5.4k
- PR merge metrics
- No merged PRs in 30d
Description
Is there an existing issue for this?
- I have searched the existing issues
Description of the Issue
The "Replace with" when replacing text shouldn't use regex.
Steps To Reproduce
Press Ctrl+Shift+F and routinely replace text in a Search Mode "Regular expression":
Text:
abcd
Find what:
ab[c]
Replace with:
ab\)
Current Behavior
ab)d
Expected Behavior
ab\)d
// the "Replace with" shouldn't use regex, it should replace the matched string as a plain text
Debug Information
Notepad++ v8.6.4 (32-bit)
Build time : Feb 20 2024 - 00:11:10
Path : C:\Program Files (x86)\Notepad++\notepad++.exe
Command Line : "C:\REDACTED.xml"
Admin mode : OFF
Local Conf mode : OFF
Cloud Config : OFF
OS Name : Windows 10 Enterprise (64-bit)
OS Version : 22H2
OS Build : 19045.5679
Current ANSI codepage : 1252
Plugins :
HexEditor (0.9.12)
mimeTools (3.1)
NppConverter (4.6)
NppExport (0.4)
Anything else?
Note: when adding a closing parenthesis ) at the end of a "Replace with", even though missing an opening parenthesis it makes it invalid, it effectively just silently drops this character. Users will be surprised when (if) double-checking their replacement results that such characters disappeared (whereas Notepad++ doesn't even inform us of the replacement result unless we manually scroll to find it, being error prone). There is no intuitive way to "convert plain text into an equivalent regex" for this purpose either. It's not intuitive, it's not documented, there is no warning about this behavior, and there is no toggle to disable it.
Note: obviously, IDEs like IntelliJ IDEA follow a proper (and logical) implementation of not using regex in the "Replace with", except for things like replacing $1 with the capture group value. Pretty much everyone will be used to this behavior over the course of their life, and when they quickly go use Notepad++ for any reason, they'll introduce severe bugs to any text they convert.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue through the Ctrl+Shift+F search-and-replace workflow with Regular expression mode enabled, using the example text and patterns in the report. Trace the replacement handling from that entry point and verify that replacement text is treated literally; done when the escaped parenthesis remains in the result as expected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- desktop, search
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100