[pacman-dev] [PATCH] libmakepkg: lint all arrays for empty values
morganamilo
morganamilo at archlinux.org
Tue Oct 27 21:44:55 UTC 2020
---
I've seen this out in the wild:
https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=vim-coc-highlight-git&id=3063e1a6d3e72a35528
diff --git a/scripts/libmakepkg/lint_pkgbuild/variable.sh.in b/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
index 1bc49722..22f5fbbb 100644
--- a/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
+++ b/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
@@ -31,7 +31,7 @@ lint_pkgbuild_functions+=('lint_variable')
lint_variable() {
- local i a pkg out bad ret=0
+ local i a pkg out bad array var ret=0
# global variables
for i in ${pkgbuild_schema_arrays[@]}; do
@@ -93,5 +93,62 @@ lint_variable() {
done
done
+ # ensure lists don't contain empty values
+ for i in ${pkgbuild_schema_arrays[@]}; do
+ if declare -p $i > /dev/null 2>&1; then
+ array_build "array" "$i"
+ for var in "${array[@]}"; do
+ if [[ -z "$var" ]]; then
+ error "$(gettext "%s is not allowed to be empty")" "$i"
+ ret=1
+ fi
+ done
+ fi
+ done
+
+ for a in ${arch[@]}; do
+ [[ $a == "any" ]] && continue
+
+ for i in ${pkgbuild_schema_arch_arrays[@]}; do
+ if declare -p "${i}_${a}" > /dev/null 2>&1; then
+ array_build "array" "${i}_${a}"
+ for var in "${array[@]}"; do
+ if [[ -z "$var" ]]; then
+ error "$(gettext "%s is not allowed to be empty")" "${i}_${a}"
+ ret=1
+ fi
+ done
+ fi
+ done
+ done
+
+ for pkg in ${pkgname[@]}; do
+ for i in ${pkgbuild_schema_arrays[@]}; do
+ if extract_function_variable "package_$pkg" $i 1 out; then
+ for val in "${out[@]}" ;do
+ if [[ -z "$val" ]]; then
+ error "$(gettext "%s is not allowed to be empty")" "$i"
+ ret=1
+ fi
+ done
+ fi
+ done
+
+ for a in ${arch[@]}; do
+ [[ $a == "any" ]] && continue
+
+ for i in ${pkgbuild_schema_arch_arrays[@]}; do
+ if extract_function_variable "package_$pkg" "${i}_${a}" 1 out; then
+ for val in "${out[@]}" ;do
+ if [[ -z "$val" ]]; then
+ error "$(gettext "%s is not allowed to be empty")" "${i}_${a}"
+ ret=1
+ fi
+ done
+ fi
+ done
+ done
+ done
+
return $ret
}
--
2.29.1
More information about the pacman-dev
mailing list