diff options
author | Christian A. Weber | 2016-07-16 18:24:08 +0200 |
---|---|---|
committer | Christian A. Weber | 2016-07-16 18:24:08 +0200 |
commit | aec4634e59713e125fa6e5ee2826ab5546db7446 (patch) | |
tree | 0b01526b0e95831ad1d36ead3e17b5c15a779ed1 | |
parent | 1f7cbb5a8a7869073d96c0f2dae45be7c0eed0c2 (diff) | |
download | itools-aec4634e59713e125fa6e5ee2826ab5546db7446.tar.gz itools-aec4634e59713e125fa6e5ee2826ab5546db7446.tar.bz2 itools-aec4634e59713e125fa6e5ee2826ab5546db7446.zip |
itjs::serialize() and itjs::encode() can encode null
-rw-r--r-- | itjs.class | 3 | ||||
-rwxr-xr-x | tests/itjs.t | 6 |
2 files changed, 9 insertions, 0 deletions
@@ -70,6 +70,9 @@ static function serialize($values, $envelope = false) */ static function encode($values) { + if ($values === null) + return 'null'; + 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); $charset = self::$charset ?: ini_get('default_charset'); diff --git a/tests/itjs.t b/tests/itjs.t index 8dff992..fce81ee 100755 --- a/tests/itjs.t +++ b/tests/itjs.t @@ -6,6 +6,12 @@ $_GET['aa'] = 1; is( + itjs::serialize(null), + 'null', + 'null' +); + +is( itjs::serialize(array()), '[]', 'empty array' |