Implement GH-15680: Enhance zend_dump_op_array to Properly Represent Non-Printable Characters in String Literals

Replaces GH-15730 as that PR became stale.

But instead of introducing a new helper, reuse
smart_str_append_escaped(), this also removes the dependency on
ext/standard.

Closes GH-15730.
Closes GH-17277.
This commit is contained in:
Niels Dossche 2024-12-26 20:09:42 +01:00
parent f0554477ae
commit 55afe8bd9b
No known key found for this signature in database
GPG key ID: B8A8AD166DF0E2E5
5 changed files with 26 additions and 15 deletions

2
NEWS
View file

@ -14,6 +14,8 @@ PHP NEWS
Volker Dusch)
. Use `clock_gettime_nsec_np()` for high resolution timer on macOS
if available. (timwolla)
. Implement GH-15680 (Enhance zend_dump_op_array to properly represent
non-printable characters in string literals). (nielsdos, WangYihang)
- Curl:
. Added curl_multi_get_handles(). (timwolla)

View file

@ -23,7 +23,7 @@
#include "zend_func_info.h"
#include "zend_call_graph.h"
#include "zend_dump.h"
#include "ext/standard/php_string.h"
#include "zend_smart_str.h"
void zend_dump_ht(HashTable *ht)
{
@ -66,13 +66,27 @@ void zend_dump_const(const zval *zv)
case IS_DOUBLE:
fprintf(stderr, " float(%g)", Z_DVAL_P(zv));
break;
case IS_STRING:;
zend_string *escaped_string = php_addcslashes(Z_STR_P(zv), "\"\\", 2);
case IS_STRING: {
smart_str escaped_string = {0};
smart_str_append_escaped(&escaped_string, Z_STRVAL_P(zv), Z_STRLEN_P(zv));
smart_str_0(&escaped_string);
fprintf(stderr, " string(\"%s\")", ZSTR_VAL(escaped_string));
fprintf(stderr, " string(\"");
zend_string_release(escaped_string);
/* Also escape '"' */
for (size_t i = 0; i < ZSTR_LEN(escaped_string.s); i++) {
if (ZSTR_VAL(escaped_string.s)[i] == '"') {
fprintf(stderr, "\\\"");
} else {
putc(ZSTR_VAL(escaped_string.s)[i], stderr);
}
}
fprintf(stderr, "\")");
smart_str_free_ex(&escaped_string, false);
break;
}
case IS_ARRAY:
fprintf(stderr, " array(...)");
break;

View file

@ -44,16 +44,14 @@ test:
; (lines=2, args=0, vars=0, tmps=0)
; (after optimizer)
; %s
0000 ECHO string("No match
")
0000 ECHO string("No match\n")
0001 RETURN null
test2:
; (lines=2, args=0, vars=0, tmps=0)
; (after optimizer)
; %s
0000 ECHO string("No match
")
0000 ECHO string("No match\n")
0001 RETURN null
No match
No match

View file

@ -50,10 +50,8 @@ Loop::test:
; (lines=3, args=0, vars=0, tmps=0)
; (after optimizer)
; %sdce_009.php:4-10
0000 ECHO string("Start
")
0001 ECHO string("Done
")
0000 ECHO string("Start\n")
0001 ECHO string("Done\n")
0002 RETURN null
Loop::test2:

View file

@ -36,8 +36,7 @@ $_main:
0004 INIT_FCALL 1 %d string("var_export")
0005 SEND_VAR CV0($x) 1
0006 DO_ICALL
0007 ECHO string("
")
0007 ECHO string("\n")
0008 JMP 0003
0009 FE_FREE V1
0010 RETURN int(1)