Search: case conversion reinterprets literal dollar sequences in captured text
- Dominant language
- TypeScript
- Stars
- 193k
- Forks
- 42.4k
- PR merge metrics
- PR metrics pending
Description
Workspace search corrupts captured text containing replacement syntax when a case modifier is applied. The dollar sequences below are part of the file content, so changing case should preserve them literally.
Does this issue occur when all extensions are disabled?: Yes. Reproduced with `--disable-extensions` and a fresh Code OSS profile.
- VS Code version: Code OSS 1.138.0 development build from `main` at `fc0a9e94576224c89cc08d390b38ab760a261f1f`.
- OS: macOS 27.0, arm64.
### Steps to reproduce
1. Open a folder containing a saved `dollars.txt` file with these three lines:
```text
foo$1
foo$&
foo$$
```
2. Open **Replace in Files** (the Search view), enable **Use Regular Expression**, and leave **Preserve Case** off.
3. Search for `^(foo.*)$` and replace with `\U$1`.
4. Inspect the replacement preview, then use **Replace All**.
| Input | Expected | Actual preview and saved file |
| --- | --- | --- |
| `foo$1` | `FOO$1` | `FOOfoo$1` |
| `foo$&` | `FOO$&` | `FOOfoo$&` |
| `foo$$` | `FOO$$` | `FOO$` |
### Cause and related reports
`replaceWithCaseOperations` converts the captured text and inserts it directly into the replacement template passed to `String.replace`. Dollar sequences in that captured text are consequently interpreted again as replacement syntax. Core regression cases also reproduce this with prefix/suffix references and named-reference text.
Related: #299365 and #326451 concern `$$` entered directly in the replacement field. This report concerns dollar sequences in the captured **file content** after case conversion. I ran the `foo$1` and `foo$$` cases against #326451's head (`6a830ff084777cc45b024028a2dd52dce8c6c842`); both still produce the incorrect results above.
Contributor guide
Assessment
This issue has not been assessed yet.