|  | 
| 23 | 23 | #include "zend_func_info.h" | 
| 24 | 24 | #include "zend_call_graph.h" | 
| 25 | 25 | #include "zend_dump.h" | 
| 26 |  | -#include "ext/standard/php_string.h" | 
|  | 26 | +#include "zend_smart_str.h" | 
| 27 | 27 | 
 | 
| 28 | 28 | void zend_dump_ht(HashTable *ht) | 
| 29 | 29 | { | 
| @@ -66,13 +66,27 @@ void zend_dump_const(const zval *zv) | 
| 66 | 66 | 		case IS_DOUBLE: | 
| 67 | 67 | 			fprintf(stderr, " float(%g)", Z_DVAL_P(zv)); | 
| 68 | 68 | 			break; | 
| 69 |  | -		case IS_STRING:; | 
| 70 |  | -			zend_string *escaped_string = php_addcslashes(Z_STR_P(zv), "\"\\", 2); | 
|  | 69 | +		case IS_STRING: { | 
|  | 70 | +			smart_str escaped_string = {0}; | 
|  | 71 | +			smart_str_append_escaped(&escaped_string, Z_STRVAL_P(zv), Z_STRLEN_P(zv)); | 
|  | 72 | +			smart_str_0(&escaped_string); | 
| 71 | 73 | 
 | 
| 72 |  | -			fprintf(stderr, " string(\"%s\")", ZSTR_VAL(escaped_string)); | 
|  | 74 | +			fprintf(stderr, " string(\""); | 
| 73 | 75 | 
 | 
| 74 |  | -			zend_string_release(escaped_string); | 
|  | 76 | +			/* Also escape '"' */ | 
|  | 77 | +			for (size_t i = 0; i < ZSTR_LEN(escaped_string.s); i++) { | 
|  | 78 | +				if (ZSTR_VAL(escaped_string.s)[i] == '"') { | 
|  | 79 | +					fprintf(stderr, "\\\""); | 
|  | 80 | +				} else { | 
|  | 81 | +					putc(ZSTR_VAL(escaped_string.s)[i], stderr); | 
|  | 82 | +				} | 
|  | 83 | +			} | 
|  | 84 | + | 
|  | 85 | +			fprintf(stderr, "\")"); | 
|  | 86 | + | 
|  | 87 | +			smart_str_free_ex(&escaped_string, false); | 
| 75 | 88 | 			break; | 
|  | 89 | +		} | 
| 76 | 90 | 		case IS_ARRAY: | 
| 77 | 91 | 			fprintf(stderr, " array(...)"); | 
| 78 | 92 | 			break; | 
|  | 
0 commit comments