Pádraig Brady <[email protected]> writes:
> * tests/env/env.sh: Add a test case ensuring
> ---
> tests/env/env.sh | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/tests/env/env.sh b/tests/env/env.sh
> index a76b40132..1ee3bc930 100755
> --- a/tests/env/env.sh
> +++ b/tests/env/env.sh
> @@ -90,6 +90,14 @@ ENV_TEST1=b
> EOF
> compare exp out || fail=1
>
> +# env shouldn't care what encoding name or value is
> +for nv in 'NON_UTF8_TEST=\240' 'NON_UTF8_TEST\240=1'; do
> + env $(printf "$nv") env > all || fail=1
> + grep '^NON_UTF8_TEST' all | LC_ALL=C sort > out || framework_failure_
> + printf "$nv\\n" > exp || framework_failure_
> + compare exp out || fail=1
> +done
> +
> # PATH modifications affect exec.
> mkdir unlikely_name || framework_failure_
> cat <<EOF > unlikely_name/also_unlikely || framework_failure_
Theoretically an implementation of putenv, setenv, etc. could fail here.
Quoting text from POSIX [1]:
These strings have the form name=value; names shall not contain any
bytes that have the encoded value of the character '='. For values
to be portable across systems conforming to POSIX.1-2024, the value
shall be composed of bytes that have the encoded value of characters
from the portable character set (except NUL and as indicated below).
Environment variable names used by the utilities in the Shell and
Utilities volume of POSIX.1-2024 consist solely of uppercase
letters, digits, and the <underscore> ('_') from the characters
defined in Portable Character Set and do not begin with a digit.
Other characters, and byte sequences that do not form valid
characters, may be permitted by an implementation; applications
shall tolerate the presence of such names. Uppercase and lowercase
letters shall retain their unique identities and shall not be folded
together.
In practice, every implementation I know of just accepts the bytes as
given and puts them into the environment. So we can ignore that
portability concern until the unlikely case it shows up.
Collin
[1]
https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/basedefs/V1_chap08.html#tag_08_01