Bug #81635 [Nab->Opn]: When curly braces are escaped, the back-slash isn't removed \{
| From: | cmb@php.net | Date: | Thu, 18 Nov 2021 11:40:49 +0000 |
| Subject: | Bug #81635 [Nab->Opn]: When curly braces are escaped, the back-slash isn't removed \{ | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-237843@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=81635&edit=1
ID: 81635
Updated by: cmb@php.net
Reported by: shealavington at gmail dot com
Summary: When curly braces are escaped, the back-slash isn't
removed \{
-Status: Not a bug
+Status: Open
Type: Bug
Package: Scripting Engine problem
Operating System: Windows 10
PHP Version: 8.0.12
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Yeah, this is actually unclear.
"hello\{$foo}"
This looks like complex string interpolation syntax, but is
apparently parsed as simple string interpolation syntax, so $foo
is being replaced with its value. So, I assume, that the
backslash acts as escape for the open *and* the closing curly
braces.
Previous Comments:
------------------------------------------------------------------------
[2021-11-18 11:31:29] shealavington at gmail dot com
Notice how with this example I actually get one output with curlys and one without, which would
suggest to me that there is a bug in the template parsing.
```
$foo = "bar";
var_dump("hello\{$foo}");
var_dump("hello\x{$foo}x");
```
------------------------------------------------------------------------
[2021-11-18 11:26:47] shealavington at gmail dot com
I now see that
\{ is not an escape sequence. However, that doesn't explain why the
following
```
$foo = "bar";
var_dump("hello\{$foo}");
```
outputs "hello\{bar}" instead of "hello\bar"... The
curly braces should act as a variable wrap and should therefore be removed?
Please do correct me if I'm mis-understanding here.
------------------------------------------------------------------------
[2021-11-18 11:21:24] cmb@php.net
The docs do not list \$ as escape sequence[1]. They are actually
very explicit about that[2]:
| Since { can not be escaped, [â¦]
What you're looking for is <https://3v4l.org/hndfP>.
[1] <https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.double>
[2] <https://www.php.net/manual/en/language.types.string.php#language.types.string.parsing.complex>
------------------------------------------------------------------------
[2021-11-18 11:06:06] shealavington at gmail dot com
Description:
------------
When curly braces are escaped within a string "", the back-slash isn't removed \{.
For example "hello\{$foo}" is outputting hello\{bar} instead of
hello{bar}
Test script:
---------------
<?php
$foo = "bar";
$test_script = "hello\{$foo}"
//- Explanation output below.
echo "If \ is the escape character, why are the escaped characters and the escape
character both shown?<br>";
echo "Res: <b>c:\path\hello\{$foo}</b><br>";
echo "Expected:
<b>c:\path\hello"."{"."$foo}</b><br>";
echo "<br>Notice how in this example, I haven't used a \ but the
{} characters are gone when not escaped?<br>";
echo "Res: <b>c:\path\hello{$foo}</b><br>";
echo "<br>If I use \ n, it replaces the \, I don't see
\ n like I do in the first example above.<br>";
echo "Res: <b>c:\path\hello\note\{$foo}</b><br>";
Expected result:
----------------
hello{bar}
Actual result:
--------------
hello\{bar}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81635&edit=1