@yuneta/gobj-js 7.26.5 → 7.26.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.
@@ -4067,15 +4067,26 @@
4067
4067
  ************************************************************/
4068
4068
  function kw_delete(gobj, kw, path) {
4069
4069
  if (gobj && !is_gobj(gobj)) log_error(`GObj bad instanceof`);
4070
+ const prefix = gobj ? gobj_short_name(gobj) + ": " : "";
4071
+ if (!is_string(path)) {
4072
+ log_error(`${prefix}kw_delete(): path must be a string: ${String(path)}`);
4073
+ return -1;
4074
+ }
4070
4075
  let [path_, k] = strrchr_split(path, "`");
4076
+ let v = kw;
4071
4077
  if (!empty_string(k)) {
4072
- let v = kw_find_path(gobj, kw, path_, true);
4073
- if (is_array(v)) {
4074
- log_error(`${gobj ? gobj_short_name(gobj) + ": " : ""}kw_delete(): cannot delete an item of a list: '${path}'`);
4075
- return -1;
4076
- }
4077
- json_object_del(v, k);
4078
- } else json_object_del(kw, path);
4078
+ v = kw_find_path(gobj, kw, path_, true);
4079
+ if (v === void 0) return -1;
4080
+ } else k = path;
4081
+ if (is_array(v)) {
4082
+ log_error(`${prefix}kw_delete(): cannot delete an item of a list: '${path}'`);
4083
+ return -1;
4084
+ }
4085
+ if (!is_object(v) || !Object.prototype.hasOwnProperty.call(v, k)) {
4086
+ log_error(`${prefix}kw_delete(): path not found: '${path}'`);
4087
+ return -1;
4088
+ }
4089
+ delete v[k];
4079
4090
  return 0;
4080
4091
  }
4081
4092
  /************************************************************
@@ -4427,6 +4438,10 @@
4427
4438
  log_error("kw is not an object");
4428
4439
  return -1;
4429
4440
  }
4441
+ if (!is_string(path)) {
4442
+ log_error(`${gobj ? gobj_short_name(gobj) + ": " : ""}kw_set_dict_value(): path must be a string: ${String(path)}`);
4443
+ return -1;
4444
+ }
4430
4445
  let ss = path.split("`");
4431
4446
  let len = ss.length;
4432
4447
  for (let i = 0; i < len; i++) {