depends, provides, conflicts, replaces, and other variables that are
meant to contain package names, are now checked to ensure they contain
only characters that would equate to a valid pkgname.

TODO: implement for makedepends/optdepends
Signed-off-by: Eli Schwartz <[email protected]>
---

quick hack that seems to work okay.

I have not yet implemented provides=('foo=1') or
optdepends=('bar: description') but this seems to work in concept.

 scripts/libmakepkg/lint_pkgbuild/pkgbase.sh.in | 19 ++------
 scripts/libmakepkg/lint_pkgbuild/pkgname.sh.in | 66 +++++++++++++++++++++-----
 2 files changed, 58 insertions(+), 27 deletions(-)

diff --git a/scripts/libmakepkg/lint_pkgbuild/pkgbase.sh.in 
b/scripts/libmakepkg/lint_pkgbuild/pkgbase.sh.in
index b2f7af04..9e77b50b 100644
--- a/scripts/libmakepkg/lint_pkgbuild/pkgbase.sh.in
+++ b/scripts/libmakepkg/lint_pkgbuild/pkgbase.sh.in
@@ -23,6 +23,7 @@ LIBMAKEPKG_LINT_PKGBUILD_PKGBASE_SH=1
 
 LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
 
+source "$LIBRARY/lint_pkgbuild/pkgname.sh"
 source "$LIBRARY/util/message.sh"
 
 
@@ -30,21 +31,9 @@ lint_pkgbuild_functions+=('lint_pkgbase')
 
 
 lint_pkgbase() {
-       local ret=0
-
-       if [[ ${pkgbase:0:1} = "-" ]]; then
-               error "$(gettext "%s is not allowed to start with a hyphen.")" 
"pkgname"
-               return 1
-       fi
-       if [[ ${pkgbase:0:1} = "." ]]; then
-               error "$(gettext "%s is not allowed to start with a dot.")" 
"pkgbase"
-               ret=1
-       fi
-       if [[ $pkgbase = *[^[:alnum:]+_.@-]* ]]; then
-               error "$(gettext "%s contains invalid characters: '%s'")" \
-                               'pkgbase' "${i//[[:alnum:]+_.@-]}"
-               ret=1
+       if [[ -z $pkgbase ]]; then
+               return 0
        fi
 
-       return $ret
+       lint_pkg_names "pkgbase" "$pkgbase"
 }
diff --git a/scripts/libmakepkg/lint_pkgbuild/pkgname.sh.in 
b/scripts/libmakepkg/lint_pkgbuild/pkgname.sh.in
index 4024253e..7d4104ce 100644
--- a/scripts/libmakepkg/lint_pkgbuild/pkgname.sh.in
+++ b/scripts/libmakepkg/lint_pkgbuild/pkgname.sh.in
@@ -26,37 +26,79 @@ LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
 source "$LIBRARY/util/message.sh"
 
 
-lint_pkgbuild_functions+=('lint_pkgname')
+lint_pkgbuild_functions+=('lint_pkgname' 'lint_pkgname_like')
 
 
-lint_pkgname() {
-       local ret=0 i
+lint_pkg_names() {
+       local type=$1 name=$2 ret=0 i
 
-       if [[ -z ${pkgname[@]} ]]; then
-               error "$(gettext "%s is not allowed to be empty.")" "pkgname"
-               return 1
-       fi
 
-       for i in "${pkgname[@]}"; do
+       for i in "${name[@]}"; do
                if [[ -z $i ]]; then
-                       error "$(gettext "%s is not allowed to be empty.")" 
"pkgname"
+                       error "$(gettext "%s is not allowed to be empty.")" 
"$type"
                        ret=1
                        continue
                fi
                if [[ ${i:0:1} = "-" ]]; then
-                       error "$(gettext "%s is not allowed to start with a 
hyphen.")" "pkgname"
+                       error "$(gettext "%s is not allowed to start with a 
hyphen.")" "$type"
                        ret=1
                fi
                if [[ ${i:0:1} = "." ]]; then
-                       error "$(gettext "%s is not allowed to start with a 
dot.")" "pkgname"
+                       error "$(gettext "%s is not allowed to start with a 
dot.")" "$type"
                        ret=1
                fi
                if [[ $i = *[^[:alnum:]+_.@-]* ]]; then
                        error "$(gettext "%s contains invalid characters: 
'%s'")" \
-                                       'pkgname' "${i//[[:alnum:]+_.@-]}"
+                                       "$type" "${i//[[:alnum:]+_.@-]}"
                        ret=1
                fi
        done
 
        return $ret
 }
+
+
+lint_pkgname_like() {
+       local a list name type ret=0
+
+       for type in conflicts depends makedepends optdepends provides replaces; 
do
+               local pkgname_like_list=()
+               if extract_global_variable "$type" 1 list; then
+                       pkgname_like_list=("${list[@]}")
+               fi
+               for a in "${arch[@]}"; do
+                       if extract_global_variable "${type}_$a" 1 list; then
+                               pkgname_like_list+=("${list[@]}")
+                       fi
+               done
+
+               for name in "${pkgname[@]}"; do
+                       if extract_function_variable "package_$name" "$type" 1 
list; then
+                               pkgname_like_list+=("${list[@]}")
+                       fi
+
+                       for a in "${arch[@]}"; do
+                               if extract_function_variable "package_$name" 
"${type}_$a" 1 list; then
+                                       pkgname_like_list+=("${list[@]}")
+                               fi
+                       done
+               done
+
+               if (( "${#pkgname_like_list[@]}" > 0 )); then
+                       lint_pkg_names "$type" "${pkgname_like_list[@]}" || 
ret=1
+               fi
+       done
+
+       return $ret
+}
+
+lint_pkgname() {
+       local ret=0
+
+       if [[ -z ${pkgname[@]} ]]; then
+               error "$(gettext "%s is not allowed to be empty.")" "pkgname"
+               ret=1
+       else
+               lint_pkg_names "pkgname" "${pkgname[@]}" || ret=1
+       fi
+}
-- 
2.16.2

Reply via email to