Skip to content

Add string output escaping into zend dump (phpdbg + opcache debug) #11337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Zend/Optimizer/zend_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "zend_func_info.h"
#include "zend_call_graph.h"
#include "zend_dump.h"
#include "ext/standard/php_string.h"

void zend_dump_ht(HashTable *ht)
{
Expand Down Expand Up @@ -65,8 +66,12 @@ void zend_dump_const(const zval *zv)
case IS_DOUBLE:
fprintf(stderr, " float(%g)", Z_DVAL_P(zv));
break;
case IS_STRING:
fprintf(stderr, " string(\"%s\")", Z_STRVAL_P(zv));
case IS_STRING:;
zend_string *escaped_string = php_addcslashes(Z_STR_P(zv), "\"\\", 2);

fprintf(stderr, " string(\"%s\")", ZSTR_VAL(escaped_string));

zend_string_release(escaped_string);
break;
case IS_ARRAY:
fprintf(stderr, " array(...)");
Expand Down
8 changes: 4 additions & 4 deletions sapi/phpdbg/tests/print_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Foo\Bar::Foo:
; (lines=5, args=1, vars=1, tmps=1)
; %s:5-7
L0005 0000 CV0($bar) = RECV 1
L0006 0001 INIT_NS_FCALL_BY_NAME 1 string("Foo\var_dump")
L0006 0001 INIT_NS_FCALL_BY_NAME 1 string("Foo\\var_dump")
L0006 0002 SEND_VAR_EX CV0($bar) 1
L0006 0003 DO_FCALL
L0007 0004 RETURN null
Expand All @@ -44,10 +44,10 @@ prompt> [Context %s (9 ops)]
$_main:
; (lines=9, args=0, vars=0, tmps=4)
; %s:1-21
L0018 0000 V0 = NEW 0 string("Foo\Bar")
L0018 0000 V0 = NEW 0 string("Foo\\Bar")
L0018 0001 DO_FCALL
L0018 0002 INIT_METHOD_CALL 1 V0 string("Foo")
L0018 0003 SEND_VAL_EX string("test") 1
L0018 0003 SEND_VAL_EX string("test \"quotes\"") 1
L0018 0004 DO_FCALL
L0019 0005 INIT_FCALL %d %d string("foo")
L0019 0006 SEND_VAL string("test") 1
Expand All @@ -72,6 +72,6 @@ namespace {
var_dump(strrev($baz));
}

(new \Foo\Bar)->Foo("test");
(new \Foo\Bar)->Foo('test "quotes"');
foo("test");
}