summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian A. Weber2016-07-16 23:17:44 +0200
committerChristian A. Weber2016-07-16 23:17:44 +0200
commita406864c30fcbb3c462b99f91c03dd1d9b30545f (patch)
treec3f54124687f9212c68f2445ead73f86815f699f
parentaec4634e59713e125fa6e5ee2826ab5546db7446 (diff)
downloaditools-a406864c30fcbb3c462b99f91c03dd1d9b30545f.tar.gz
itools-a406864c30fcbb3c462b99f91c03dd1d9b30545f.tar.bz2
itools-a406864c30fcbb3c462b99f91c03dd1d9b30545f.zip
itjs::encode() can encode non-arrays
-rw-r--r--itjs.class4
-rwxr-xr-xtests/itjs.t6
2 files changed, 8 insertions, 2 deletions
diff --git a/itjs.class b/itjs.class
index b5672c0..d2805e7 100644
--- a/itjs.class
+++ b/itjs.class
@@ -70,8 +70,8 @@ static function serialize($values, $envelope = false)
*/
static function encode($values)
{
- if ($values === null)
- return 'null';
+ if (!is_array($values))
+ return json_encode($values, JSON_UNESCAPED_UNICODE);
static $jskeyword = array("abstract" => 1, "boolean" => 1, "break" => 1, "byte" => 1, "case" => 1, "catch" => 1, "char" => 1, "class" => 1, "const" => 1, "continue" => 1, "debugger" => 1, "default" => 1, "delete" => 1, "do" => 1, "double" => 1, "each" => 1, "else" => 1, "enum" => 1, "export" => 1, "extends" => 1, "false" => 1, "final" => 1, "finally" => 1, "float" => 1, "for" => 1, "function" => 1, "goto" => 1, "if" => 1, "implements" => 1, "import" => 1, "in" => 1, "instanceof" => 1, "int" => 1, "interface" => 1, "long" => 1, "namespace" => 1, "native" => 1, "new" => 1, "null" => 1, "package" => 1, "private" => 1, "protected" => 1, "public" => 1, "return" => 1, "short" => 1, "static" => 1, "super" => 1, "switch" => 1, "synchronized" => 1, "this" => 1, "throw" => 1, "throws" => 1, "transient" => 1, "true" => 1, "try" => 1, "typeof" => 1, "var" => 1, "void" => 1, "volatile" => 1, "while" => 1, "with" => 1, "xml" => 1);
diff --git a/tests/itjs.t b/tests/itjs.t
index fce81ee..695ccd8 100755
--- a/tests/itjs.t
+++ b/tests/itjs.t
@@ -58,3 +58,9 @@ is(
"{'foo\'foo':\"bar\"}",
"quote ' in keys"
);
+
+is(
+ itjs::serialize("hellö"),
+ '"hellö"',
+ "string"
+);