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