Skip to content

Commit b495a91

Browse files
authored
Add string output escaping into zend dump (phpdbg + opcache debug) (#11337)
* Add string output escaping into zend dump (phpdbg + opcache debug) * Use ZSTR_VAL macro instead direct string access * Move "escaped_string" into local switch/case scope * Add zend_string_release * Add Z_STR_P macro instead direct string access * Merge zend_string declaration and its assigment in one stmt
1 parent 99ec0c1 commit b495a91

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

Zend/Optimizer/zend_dump.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "zend_func_info.h"
2424
#include "zend_call_graph.h"
2525
#include "zend_dump.h"
26+
#include "ext/standard/php_string.h"
2627

2728
void zend_dump_ht(HashTable *ht)
2829
{
@@ -65,8 +66,12 @@ void zend_dump_const(const zval *zv)
6566
case IS_DOUBLE:
6667
fprintf(stderr, " float(%g)", Z_DVAL_P(zv));
6768
break;
68-
case IS_STRING:
69-
fprintf(stderr, " string(\"%s\")", Z_STRVAL_P(zv));
69+
case IS_STRING:;
70+
zend_string *escaped_string = php_addcslashes(Z_STR_P(zv), "\"\\", 2);
71+
72+
fprintf(stderr, " string(\"%s\")", ZSTR_VAL(escaped_string));
73+
74+
zend_string_release(escaped_string);
7075
break;
7176
case IS_ARRAY:
7277
fprintf(stderr, " array(...)");

sapi/phpdbg/tests/print_001.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Foo\Bar::Foo:
2929
; (lines=5, args=1, vars=1, tmps=1)
3030
; %s:5-7
3131
L0005 0000 CV0($bar) = RECV 1
32-
L0006 0001 INIT_NS_FCALL_BY_NAME 1 string("Foo\var_dump")
32+
L0006 0001 INIT_NS_FCALL_BY_NAME 1 string("Foo\\var_dump")
3333
L0006 0002 SEND_VAR_EX CV0($bar) 1
3434
L0006 0003 DO_FCALL
3535
L0007 0004 RETURN null
@@ -44,10 +44,10 @@ prompt> [Context %s (9 ops)]
4444
$_main:
4545
; (lines=9, args=0, vars=0, tmps=4)
4646
; %s:1-21
47-
L0018 0000 V0 = NEW 0 string("Foo\Bar")
47+
L0018 0000 V0 = NEW 0 string("Foo\\Bar")
4848
L0018 0001 DO_FCALL
4949
L0018 0002 INIT_METHOD_CALL 1 V0 string("Foo")
50-
L0018 0003 SEND_VAL_EX string("test") 1
50+
L0018 0003 SEND_VAL_EX string("test \"quotes\"") 1
5151
L0018 0004 DO_FCALL
5252
L0019 0005 INIT_FCALL %d %d string("foo")
5353
L0019 0006 SEND_VAL string("test") 1
@@ -72,6 +72,6 @@ namespace {
7272
var_dump(strrev($baz));
7373
}
7474

75-
(new \Foo\Bar)->Foo("test");
75+
(new \Foo\Bar)->Foo('test "quotes"');
7676
foo("test");
7777
}

0 commit comments

Comments
 (0)