[pacman-dev] libmakepkg/lint_pkgbuild: check for invalid variables even if they're empty
diff mbox

Message ID 20180613011718.4103-1-eschwartz@archlinux.org
State New
Headers show

Commit Message

Eli Schwartz June 13, 2018, 1:17 a.m. UTC
Checking the length of the variable to be non-zero before considering it
an error is inconsistent; license=() and depends='' and `declare arch`
should be considered just as wrong.

In fact the current check detects depends='' as non-zero and returns an
error, but happily considers the others to be perfectly okay.

A more reliable check is to simply see if the name has been declared
(whether it is set or not), and then enforce that it's been declared to
the right type.

As an added benefit, avoiding the creation of proxy-evaled variables to
count the number of indexes results in simpler code.

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
---
 scripts/libmakepkg/lint_pkgbuild/variable.sh.in | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

Patch
diff mbox

diff --git a/scripts/libmakepkg/lint_pkgbuild/variable.sh.in b/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
index 3266cb5e..52bb61a9 100644
--- a/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
+++ b/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
@@ -37,12 +37,11 @@  lint_variable() {
 	                  replaces sha1sums sha256sums sha384sums sha512sums source)
 	local string=(changelog epoch install pkgdesc pkgrel pkgver url)
 
-	local i a v pkg keys out bad ret=0
+	local i a pkg out bad ret=0
 
 	# global variables
 	for i in ${array[@]} ${arch_array[@]}; do
-		eval "keys=(\"\${!$i[@]}\")"
-		if (( ${#keys[*]} > 0 )); then
+		if declare -p $i > /dev/null 2>&1; then
 			if ! is_array $i; then
 				error "$(gettext "%s should be an array")" "$i"
 				ret=1
@@ -54,11 +53,9 @@  lint_variable() {
 		[[ $a == "any" ]] && continue
 
 		for i in ${arch_array[@]}; do
-			v="${i}_${a}"
-			eval "keys=(\"\${!${v}[@]}\")"
-			if (( ${#keys[*]} > 0 )); then
-				if ! is_array $v; then
-					error "$(gettext "%s_%s should be an array")" "$i" "$a"
+			if declare -p "${i}_${a}" > /dev/null 2>&1; then
+				if ! is_array ${i}_${a}; then
+					error "$(gettext "%s should be an array")" "${i}_${a}"
 					ret=1
 				fi
 			fi
@@ -66,8 +63,7 @@  lint_variable() {
 	done
 
 	for i in ${string[@]}; do
-		eval "keys=(\"\${!$i[@]}\")"
-		if (( ${#keys[*]} > 0 )); then
+		if declare -p "$i" > /dev/null 2>&1; then
 			if is_array $i; then
 				error "$(gettext "%s should not be an array")" "$i"
 				ret=1