@yuneta/gobj-js 7.25.6 → 7.25.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -558,7 +558,11 @@ kw_get_dict_value(gobj, kw, path, default_value, flag)
558
558
  // KW_EXTRACT takes out only a value the reader answers with: a value
559
559
  // of another type stays in the kw.
560
560
 
561
- kw_set_dict_value(gobj, kw, path, value)
561
+ kw_set_dict_value(gobj, kw, path, value) // 0, or -1 logged
562
+ // A middle segment that is null or a scalar cannot hold the path:
563
+ // kw_set_dict_value() logs and answers -1, the kw is left as it was,
564
+ // and a reader with KW_CREATE answers its default (as C):
565
+ // kw_get_int(gobj, {a: null}, "a`b", 5, KW_CREATE) → 5, kw unchanged
562
566
  kw_set_subdict_value(gobj, kw, path, key, value)
563
567
 
564
568
  kw_match_simple(kw, filter) // → boolean
@@ -3978,7 +3978,12 @@ function kw_set_dict_value(gobj, kw, path, value) {
3978
3978
  let key = ss[i];
3979
3979
  if (i === len - 1) kw[key] = value;
3980
3980
  else {
3981
- if (kw[key] === void 0) kw[key] = {};
3981
+ let seg = kw[key];
3982
+ if (seg === void 0) kw[key] = {};
3983
+ else if (!is_object(seg) && !is_array(seg)) {
3984
+ log_error(`${gobj ? gobj_short_name(gobj) + ": " : ""}kw_set_dict_value(): segment '${key}' is not a dict or a list: '${path}'`);
3985
+ return -1;
3986
+ }
3982
3987
  kw = kw[key];
3983
3988
  }
3984
3989
  }