summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUrban Müller2015-08-10 13:59:59 +0200
committerUrban Müller2015-08-10 13:59:59 +0200
commit534899acf620b83936a8e445c806cc481d789050 (patch)
tree89af2ecb4e41303398fc5679c692c9579cc61f58
parent7fd4e76f58d377cf978f97200145167eeb2aab9e (diff)
downloaditools-534899acf620b83936a8e445c806cc481d789050.tar.gz
itools-534899acf620b83936a8e445c806cc481d789050.tar.bz2
itools-534899acf620b83936a8e445c806cc481d789050.zip
correctly handle non-utf8 in keys
-rw-r--r--it.class4
-rwxr-xr-xtests/it.t1
2 files changed, 3 insertions, 2 deletions
diff --git a/it.class b/it.class
index 8faac1f..e6f8006 100644
--- a/it.class
+++ b/it.class
@@ -429,8 +429,8 @@ static function any2utf8($value, $errprefix = "")
if (is_array($value))
{
foreach ($value as $idx => $v)
- if (is_string($v) || is_array($v))
- $value[$idx] = self::any2utf8($v, $errprefix);
+ $newarr[self::any2utf8($idx)] = is_string($v) || is_array($v) ? self::any2utf8($v, $errprefix) : $v;
+ $value = $newarr;
}
else if (is_string($value))
{
diff --git a/tests/it.t b/tests/it.t
index a50b4dc..57c8be1 100755
--- a/tests/it.t
+++ b/tests/it.t
@@ -389,6 +389,7 @@ is(it::any2utf8("a💚b"), "a💚b", "it::any2utf8 correctly handles 4-byte utf-
is(it::any2utf8(array("foo", utf8_decode("bär"))), array("foo", "bär"), "any2utf8 on arrays");
is(it::any2utf8(array("foo", array(utf8_decode("bär")))), array("foo", array("bär")), "any2utf8 on recursive arrays");
is(it::any2utf8(array(1, true, false, null)), array(1, true, false, null), "any2utf8 should leave types alone");
+is(it::any2utf8(array(utf8_decode('Müller') => utf8_decode('Müller'))), array('Müller' => 'Müller'), "it::any2utf8 latin1 keys");
foreach (array($dummy, false, true, null, 1, "a", "Ä", "/", array()) as $var)
is(it::json_decode(it::json_encode($var)), $var);