[njs] Treating null and undefined as empty string for external prop set.

Dmitry Volyntsev xeioex at nginx.com
Tue Mar 26 12:53:46 UTC 2019


details:   https://hg.nginx.org/njs/rev/c2c8cc00176f
branches:  
changeset: 843:c2c8cc00176f
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Tue Mar 26 15:28:18 2019 +0300
description:
Treating null and undefined as empty string for external prop set.

diffstat:

 njs/njs_object.c |  11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diffs (21 lines):

diff -r b758915e2406 -r c2c8cc00176f njs/njs_object.c
--- a/njs/njs_object.c	Tue Mar 26 14:51:03 2019 +0300
+++ b/njs/njs_object.c	Tue Mar 26 15:28:18 2019 +0300
@@ -684,9 +684,14 @@ njs_external_property_set(njs_vm_t *vm, 
 
     pq = (njs_property_query_t *) vm->stash;
 
-    ret = njs_vm_value_to_ext_string(vm, &s, setval, 0);
-    if (nxt_slow_path(ret != NXT_OK)) {
-        return ret;
+    if (!njs_is_null_or_undefined(setval)) {
+        ret = njs_vm_value_to_ext_string(vm, &s, setval, 0);
+        if (nxt_slow_path(ret != NXT_OK)) {
+            return ret;
+        }
+
+    } else {
+        s = nxt_string_value("");
     }
 
     *retval = *setval;


More information about the nginx-devel mailing list