]> git.kaiwu.me - njs.git/commitdiff
Fixed equality operator with "null" value as right operand.
authorValentin Bartenev <vbart@nginx.com>
Fri, 9 Nov 2018 15:05:39 +0000 (18:05 +0300)
committerValentin Bartenev <vbart@nginx.com>
Fri, 9 Nov 2018 15:05:39 +0000 (18:05 +0300)
njs/njs_vm.c
njs/test/njs_unit_test.c

index b56f1ff338ab826c4232f746602eb9782bebd8bb..dd59ae060bb77612c387fa4b3da9d03eb8e60d26 100644 (file)
@@ -1519,9 +1519,14 @@ njs_vmcode_not_equal(njs_vm_t *vm, njs_value_t *val1, njs_value_t *val2)
 static nxt_noinline njs_ret_t
 njs_values_equal(njs_vm_t *vm, const njs_value_t *val1, const njs_value_t *val2)
 {
+    nxt_bool_t  nv1, nv2;
+
+    nv1 = njs_is_null_or_void(val1);
+    nv2 = njs_is_null_or_void(val2);
+
     /* Void and null are equal and not comparable with anything else. */
-    if (njs_is_null_or_void(val1)) {
-        return (njs_is_null_or_void(val2));
+    if (nv1 || nv2) {
+        return (nv1 && nv2);
     }
 
     if (njs_is_numeric(val1) && njs_is_numeric(val2)) {
index d605a67b2be2070b6779f709cf8f5d69cf7fb5b5..e35e43366ecce4f61ab9300eac5475366c9fc322 100644 (file)
@@ -1025,6 +1025,9 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("null == false"),
       nxt_string("false") },
 
+    { nxt_string("0 == null"),
+      nxt_string("false") },
+
     { nxt_string("!null"),
       nxt_string("true") },