From 91b72cc386ca03241791748da5da2b150c724ace Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Tue, 3 Apr 2018 17:48:14 -0400 Subject: libmakepkg/lint_pkgbuild: lint depends/etc. as if they are pkgname depends, provides, conflicts, replaces, and other variables that are meant to contain package names, are now checked to ensure 1) the name component contains only characters that would equate to a valid pkgname. 2) the version component contains only characters that would equate to a valid pkgver. 3) comparison operator is a valid comparison operator (e.g. provides only allows exact = while optdepends doesn't allow anything) This also refactors pkgname into a shared utility function, wires up pkgbase optdepends and provides to use it, and gives pkgver a touchup to allow referencing where it was called from. Fixes FS#57833 and a bit of extra. Signed-off-by: Eli Schwartz Signed-off-by: Allan McRae --- scripts/libmakepkg/lint_pkgbuild/pkgname.sh.in | 53 +++++++++++++++----------- 1 file changed, 31 insertions(+), 22 deletions(-) (limited to 'scripts/libmakepkg/lint_pkgbuild/pkgname.sh.in') diff --git a/scripts/libmakepkg/lint_pkgbuild/pkgname.sh.in b/scripts/libmakepkg/lint_pkgbuild/pkgname.sh.in index 4024253e..d51c6313 100644 --- a/scripts/libmakepkg/lint_pkgbuild/pkgname.sh.in +++ b/scripts/libmakepkg/lint_pkgbuild/pkgname.sh.in @@ -29,34 +29,43 @@ source "$LIBRARY/util/message.sh" lint_pkgbuild_functions+=('lint_pkgname') +lint_one_pkgname() { + local type=$1 name=$2 ret=0 + + + if [[ -z $name ]]; then + error "$(gettext "%s is not allowed to be empty.")" "$type" + ret=1 + continue + fi + if [[ ${name:0:1} = "-" ]]; then + error "$(gettext "%s is not allowed to start with a hyphen.")" "$type" + ret=1 + fi + if [[ ${name:0:1} = "." ]]; then + error "$(gettext "%s is not allowed to start with a dot.")" "$type" + ret=1 + fi + if [[ $name = *[^[:alnum:]+_.@-]* ]]; then + error "$(gettext "%s contains invalid characters: '%s'")" \ + "$type" "${name//[[:alnum:]+_.@-]}" + ret=1 + fi + + return $ret +} + lint_pkgname() { local ret=0 i if [[ -z ${pkgname[@]} ]]; then error "$(gettext "%s is not allowed to be empty.")" "pkgname" - return 1 + ret=1 + else + for i in "${pkgname[@]}"; do + lint_one_pkgname "pkgname" "$i" || ret=1 + done fi - for i in "${pkgname[@]}"; do - if [[ -z $i ]]; then - error "$(gettext "%s is not allowed to be empty.")" "pkgname" - ret=1 - continue - fi - if [[ ${i:0:1} = "-" ]]; then - error "$(gettext "%s is not allowed to start with a hyphen.")" "pkgname" - ret=1 - fi - if [[ ${i:0:1} = "." ]]; then - error "$(gettext "%s is not allowed to start with a dot.")" "pkgname" - ret=1 - fi - if [[ $i = *[^[:alnum:]+_.@-]* ]]; then - error "$(gettext "%s contains invalid characters: '%s'")" \ - 'pkgname' "${i//[[:alnum:]+_.@-]}" - ret=1 - fi - done - return $ret } -- cgit v1.2.3-54-g00ecf