Browse Source

Fixed bug #25758 (var_export does not escape ' & \ inside array keys)

PEAR_1_4DEV
Ilia Alshanetsky 23 years ago
parent
commit
6f8b8ade45
  1. 14
      ext/standard/tests/array/bug25758.phpt
  2. 6
      ext/standard/var.c

14
ext/standard/tests/array/bug25758.phpt

@ -0,0 +1,14 @@
--TEST--
Bug #25758 (var_export does not escape ' & \ inside array keys)
--FILE--
<?php
$a = array ("quote'" => array("quote'"));
echo var_export($a, true);
?>
--EXPECT--
array (
'quote\'' =>
array (
0 => 'quote\'',
),
)

6
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");

Loading…
Cancel
Save