diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-25 13:12:28 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-25 23:47:47 +0900 |
| commit | 1b42bff7d960082d7fbd6158ec226e38899c0ca9 (patch) | |
| tree | b03c473e5a9f720216266e3addbeb649d60befdc /crates/shirabe-php-shim | |
| parent | 0a3b5a997b2c1c157cf7d97cff02ec9107b85ce1 (diff) | |
| download | php-shirabe-1b42bff7d960082d7fbd6158ec226e38899c0ca9.tar.gz php-shirabe-1b42bff7d960082d7fbd6158ec226e38899c0ca9.tar.zst php-shirabe-1b42bff7d960082d7fbd6158ec226e38899c0ca9.zip | |
fix(preg): treat escaped \$ in replacement as a literal dollar sign
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-php-shim')
| -rw-r--r-- | crates/shirabe-php-shim/src/preg.rs | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/crates/shirabe-php-shim/src/preg.rs b/crates/shirabe-php-shim/src/preg.rs index 3d36137..56aa402 100644 --- a/crates/shirabe-php-shim/src/preg.rs +++ b/crates/shirabe-php-shim/src/preg.rs @@ -441,6 +441,12 @@ fn php_replacement_expand(template: &str, caps: ®ex::Captures, out: &mut Vec< out.push(b'\\'); i += 2; } + // A backslash escapes a following `$`, yielding a literal dollar sign (so an escaped + // `\$1` is not mistaken for the `$1` backreference). + b'\\' if i + 1 < bytes.len() && bytes[i + 1] == b'$' => { + out.push(b'$'); + i += 2; + } b'$' if i + 1 < bytes.len() && bytes[i + 1] == b'{' => { let rest = &bytes[i + 2..]; match rest.iter().position(|&b| b == b'}') { |
