]> granicus.if.org Git - jq/commitdiff
Fix a bug uncovered by tests extracted from manual.
authorStephen Dolan <mu@netsoc.tcd.ie>
Sun, 16 Dec 2012 13:10:48 +0000 (13:10 +0000)
committerStephen Dolan <mu@netsoc.tcd.ie>
Sun, 16 Dec 2012 13:10:48 +0000 (13:10 +0000)
`null | length` should give 0, and now does.

builtin.c

index f046e91a58adbf29b3da804197c78fcc253426c4..4f9fab59c2ea06737d2f2cfd5938c6780707c2e4 100644 (file)
--- a/builtin.c
+++ b/builtin.c
@@ -191,6 +191,9 @@ static jv f_length(jv input) {
     return jv_number(jv_object_length(input));
   } else if (jv_get_kind(input) == JV_KIND_STRING) {
     return jv_number(jv_string_length(input));
+  } else if (jv_get_kind(input) == JV_KIND_NULL) {
+    jv_free(input);
+    return jv_number(0);
   } else {
     return type_error(input, "has no length");
   }