]> granicus.if.org Git - php/commitdiff
Fixed bug #25758 (var_export does not escape ' & \ inside array keys)
authorIlia Alshanetsky <iliaa@php.net>
Wed, 8 Oct 2003 01:16:44 +0000 (01:16 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Wed, 8 Oct 2003 01:16:44 +0000 (01:16 +0000)
ext/standard/tests/array/bug25758.phpt [new file with mode: 0644]
ext/standard/var.c

diff --git a/ext/standard/tests/array/bug25758.phpt b/ext/standard/tests/array/bug25758.phpt
new file mode 100644 (file)
index 0000000..ff97d2e
--- /dev/null
@@ -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\'',
+  ),
+)
index b1732e480597d7a98d64e35f239c2b79d18f5f1e..a8e96bec52b4dbc8e2c4f41490fe6ef43d104ef8 100644 (file)
@@ -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");