From c7faa8ccec50c023c1e7daf39dba9cd02eaf3fa7 Mon Sep 17 00:00:00 2001 From: Valentin Bartenev Date: Fri, 9 Nov 2018 18:05:39 +0300 Subject: [PATCH] Fixed equality operator with "null" value as right operand. --- njs/njs_vm.c | 9 +++++++-- njs/test/njs_unit_test.c | 3 +++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/njs/njs_vm.c b/njs/njs_vm.c index b56f1ff3..dd59ae06 100644 --- a/njs/njs_vm.c +++ b/njs/njs_vm.c @@ -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)) { diff --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index d605a67b..e35e4336 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -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") }, -- 2.47.3