commit:     116645c35885a32b994e49794aa60e9c8216ba9b
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Wed Aug 14 06:23:25 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Thu Aug 22 19:37:46 2024 +0000
URL:        
https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=116645c3

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 <AT> plushkava.net>

 functions.sh | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

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}:
                                        ;;
                                *)

Reply via email to