[njs] Fixed equality operator with "null" value as right operand.
Valentin Bartenev
vbart at nginx.com
Fri Nov 9 15:06:01 UTC 2018
details: http://hg.nginx.org/njs/rev/abec5f8d55a1
branches:
changeset: 644:abec5f8d55a1
user: Valentin Bartenev <vbart at nginx.com>
date: Fri Nov 09 18:05:39 2018 +0300
description:
Fixed equality operator with "null" value as right operand.
diffstat:
njs/njs_vm.c | 9 +++++++--
njs/test/njs_unit_test.c | 3 +++
2 files changed, 10 insertions(+), 2 deletions(-)
diffs (33 lines):
diff -r c5a3ac902bc2 -r abec5f8d55a1 njs/njs_vm.c
--- a/njs/njs_vm.c Thu Nov 08 16:45:54 2018 +0300
+++ b/njs/njs_vm.c Fri Nov 09 18:05:39 2018 +0300
@@ -1519,9 +1519,14 @@ njs_vmcode_not_equal(njs_vm_t *vm, njs_v
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 -r c5a3ac902bc2 -r abec5f8d55a1 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c Thu Nov 08 16:45:54 2018 +0300
+++ b/njs/test/njs_unit_test.c Fri Nov 09 18:05:39 2018 +0300
@@ -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") },
More information about the nginx-devel
mailing list