From: William Ahern Date: Thu, 11 Aug 2022 03:58:55 +0000 (-0700) Subject: escape glob pattern special characters in subject string before generating search... X-Git-Tag: v1.5.4^2~164^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F3241%2Fhead;p=thirdparty%2Fzstd.git escape glob pattern special characters in subject string before generating search patterns in combine.sh list_has_item --- diff --git a/build/single_file_libs/combine.sh b/build/single_file_libs/combine.sh index 515bf18c6..222c2c32a 100755 --- a/build/single_file_libs/combine.sh +++ b/build/single_file_libs/combine.sh @@ -74,6 +74,24 @@ is_pragma_once_line() { # (originally used grep -Eq "(^|\s*)$2(\$|\s*)) readonly list_FS="$IFS" list_has_item() { + # Re: escaping glob pattern special characters in item string: + # + # bash (tested 3.2.57, 5.1.4), dash (tested 0.5.10.2), NetBSD /bin/sh + # (tested 8.2), and Solaris /bin/sh (tested 11.4) require escaping + # backslashes in a bracket expression despite POSIX specifying that + # backslash loses significance in a bracket expression. + # + # Conversely, neither FreeBSD /bin/sh (tested 12.2) nor OpenBSD /bin/sh + # (tested 7.1) obey backslash-escaping in case statement patterns even + # outside bracket expressions, so escape special characters using bracket + # expressions. + # + # Solaris /bin/sh (tested 11.4) requires vertical bar (|) to be escaped. + # + # All accommodations should behave as expected under strict POSIX semantics. + if fnmatch "*[\\*?[|]*" "$2"; then + set -- "$1" "$(printf '%s\n' "$2" | sed -e 's/[*?[|]/[&]/g; s/[\]/[\\&]/g')" + fi for item_P in "*[$list_FS]$2[$list_FS]*" "*[$list_FS]$2" "$2[$list_FS]*" "$2"; do fnmatch "${item_P}" "$1" && return 0 done