Просмотр исходного кода

cli: fix editor remove call validation

Skip type validation, fix passing values to remove

Signed-off-by: Felix Fietkau <[email protected]>
Felix Fietkau 5 месяцев назад
Родитель
Сommit
bd073e5cd9
1 измененных файлов с 11 добавлено и 0 удалено
  1. 11 0
      package/utils/cli/files/usr/share/ucode/cli/object-editor.uc

+ 11 - 0
package/utils/cli/files/usr/share/ucode/cli/object-editor.uc

@@ -136,10 +136,18 @@ export function remove_call(ctx, argv, named)
 			continue;
 
 		for (let idx in val) {
+			let orig_idx = idx;
 			if (idx != "" + +idx) {
 				let cur_idx = index(data, idx);
 				if (cur_idx >= 0)
 					idx = cur_idx + 1;
+				else
+					idx = null;
+			} else if (+idx > length(data))
+				idx = null;
+			if (idx == null) {
+				ctx.invalid_argument('Invalid value: %s', orig_idx);
+				continue;
 			}
 			data[+idx - 1] = null;
 		}
@@ -148,6 +156,8 @@ export function remove_call(ctx, argv, named)
 		if (cur.attribute_allow_empty && !length(cur_obj[name]))
 			delete cur_obj[name];
 	}
+	if (length(ctx.result.errors) > 0)
+		return;
 	call_change_cb(ctx, this, argv, named);
 	return ctx.ok();
 };
@@ -249,6 +259,7 @@ function remove_params(orig_params)
 			type: "enum",
 			get_object: val.get_object,
 			attribute: val.attribute ?? name,
+			no_validate: true,
 			value: param_values,
 			force_helptext: true,
 		};