From: Ilia Alshanetsky Date: Wed, 8 Oct 2003 01:16:44 +0000 (+0000) Subject: Fixed bug #25758 (var_export does not escape ' & \ inside array keys) X-Git-Tag: RELEASE_1_3b3~94 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6f8b8ade456d5ab35c174da2132cf5575e230d71;p=php Fixed bug #25758 (var_export does not escape ' & \ inside array keys) --- diff --git a/ext/standard/tests/array/bug25758.phpt b/ext/standard/tests/array/bug25758.phpt new file mode 100644 index 0000000000..ff97d2e3fb --- /dev/null +++ b/ext/standard/tests/array/bug25758.phpt @@ -0,0 +1,14 @@ +--TEST-- +Bug #25758 (var_export does not escape ' & \ inside array keys) +--FILE-- + array("quote'")); + echo var_export($a, true); +?> +--EXPECT-- +array ( + 'quote\'' => + array ( + 0 => 'quote\'', + ), +) diff --git a/ext/standard/var.c b/ext/standard/var.c index b1732e4805..a8e96bec52 100644 --- a/ext/standard/var.c +++ b/ext/standard/var.c @@ -271,7 +271,11 @@ static int php_array_element_export(zval **zv, int num_args, va_list args, zend_ if (hash_key->nKeyLength==0) { /* numeric key */ php_printf("%*c%ld => ", level + 1, ' ', hash_key->h); } else { /* string key */ - php_printf("%*c'%s' => ", level + 1, ' ', hash_key->arKey); + char *key; + int key_len; + key = php_addcslashes(hash_key->arKey, strlen(hash_key->arKey), &key_len, 0, "'\\", 2 TSRMLS_CC); + php_printf("%*c'%s' => ", level + 1, ' ', key); + efree(key); } php_var_export(zv, level + 2 TSRMLS_CC); PUTS (",\n");