[type/__uci_section] Check __object_id for syntax errors
This commit is contained in:
parent
3a6b085145
commit
c37253b852
1 changed files with 26 additions and 0 deletions
|
@ -33,6 +33,32 @@ append_values() {
|
||||||
"$@" </dev/null
|
"$@" </dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uci_validate_name() {
|
||||||
|
# like util.c uci_validate_name()
|
||||||
|
test -n "$*" && test -z "$(echo "$*" | tr -d '[:alnum:]_')"
|
||||||
|
}
|
||||||
|
|
||||||
|
## Check section name and error if invalid!
|
||||||
|
case ${__object_id:?}
|
||||||
|
in
|
||||||
|
(*.*)
|
||||||
|
uci_validate_name "${__object_id%%.*}" || {
|
||||||
|
printf 'Invalid package name: %s\n' "${__object_id%%.*}" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
uci_validate_name "${__object_id#*.}" || {
|
||||||
|
printf 'Invalid section name: %s\n' "${__object_id#*.}" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
;;
|
||||||
|
(*)
|
||||||
|
uci_validate_name "${__object_id:?}" || {
|
||||||
|
printf 'Invalid section name: %s\n' "${__object_id:?}" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
section=$(cat "${__object:?}/explorer/match")
|
section=$(cat "${__object:?}/explorer/match")
|
||||||
|
|
||||||
state_should=$(cat "${__object:?}/parameter/state")
|
state_should=$(cat "${__object:?}/parameter/state")
|
||||||
|
|
Loading…
Reference in a new issue