summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKerin Millar <kfm@plushkava.net>2024-08-14 07:23:25 +0100
committerKerin Millar <kfm@plushkava.net>2024-08-22 20:37:46 +0100
commit116645c35885a32b994e49794aa60e9c8216ba9b (patch)
tree6ff645148137f09b15a23da9f170f285e3cb1823
parentPrint a diagnostic message if no modules can be found (diff)
downloadgentoo-functions-116645c35885a32b994e49794aa60e9c8216ba9b.tar.gz
gentoo-functions-116645c35885a32b994e49794aa60e9c8216ba9b.tar.bz2
gentoo-functions-116645c35885a32b994e49794aa60e9c8216ba9b.zip
Have whenceforth() work around a word splitting bug in OpenBSD sh
Consider the case where IFS consists of a single character whose value is neither <space>, <tab> nor <newline>. The following example employs the colon, since it is the character that the whenceforth() function relies upon during word splitting. $ bash -c 'IFS=":"; path=":"; set -- $path; echo "$# ${1@Q}"' 1 '' The result is very much as expected because the colon in path serves as a terminator for an empty field. Now, let's consider how many fields are produced in OpenBSD sh as a consequence of word splitting. $ sh -c 'IFS=":"; path=":"; set -- $path; echo "$#"' 0 For the time being, work around it by having whenceforth() repeat the field terminator for the affected edge cases, which are two in number. With this change, the test suite is now able to pass for: - loksh 7.5 - oksh 7.5 - sh (OpenBSD 7.5) Signed-off-by: Kerin Millar <kfm@plushkava.net>
-rw-r--r--functions.sh10
1 files changed, 9 insertions, 1 deletions
diff --git a/functions.sh b/functions.sh
index 6cf7439..1a87100 100644
--- a/functions.sh
+++ b/functions.sh
@@ -759,7 +759,15 @@ whenceforth()
# Relative command paths must be searched for in PATH.
# https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_03
case ${PATH} in
- ''|*:)
+ ''|:)
+ # Work around a bug in OpenBSD sh and
+ # its ports. Where IFS has a value of
+ # ":", splitting a word having the same
+ # value produces no words at all. Handle
+ # it by repeating the field terminator.
+ path=::
+ ;;
+ *:)
path=${PATH}:
;;
*)