hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit c056090fa3a5e6ddd536f40410d7a624d1ed71b7
parent 8743d782c9c6acea58579748e0a45766eb2a8eb4
Author: Ember Sawady <ecs@d2evs.net>
Date:   Wed, 10 May 2023 20:56:30 +0000

os::exec::{un,}setenv: loosen restrictions on keys

The referenced section of POSIX is only relevant for shell variables.
Per https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html,
the key can't contain '=' or NUL, and must be restricted to the portable
character set. However, there's no reason to error out on valid utf8, so
only check for '=' and '\0'.

Signed-off-by: Ember Sawady <ecs@d2evs.net>

Diffstat:
Mos/exec/cmd.ha | 24+++---------------------
1 file changed, 3 insertions(+), 21 deletions(-)

diff --git a/os/exec/cmd.ha b/os/exec/cmd.ha @@ -97,25 +97,9 @@ export fn clearenv(cmd: *command) void = { }; // Removes a variable in the command environment. This does not affect the -// current process environment. The 'key' must be a valid environment variable -// name per POSIX definition 3.235. This includes underscores and alphanumeric -// ASCII characters, and cannot begin with a number. +// current process environment. The key may not contain '=' or '\0'. export fn unsetenv(cmd: *command, key: str) (void | errors::invalid) = { - let iter = strings::iter(key); - for (let i = 0z; true; i += 1) match (strings::next(&iter)) { - case void => - break; - case let r: rune => - if (i == 0) { - if(!(r == '_' || ascii::isalpha(r))) { - return errors::invalid; - }; - } else { - if(!(r == '_' || ascii::isalnum(r))) { - return errors::invalid; - }; - }; - }; + if (strings::contains(key, '=', '\0')) return errors::invalid; // XXX: This can be a binary search let fullkey = strings::concat(key, "="); @@ -131,9 +115,7 @@ export fn unsetenv(cmd: *command, key: str) (void | errors::invalid) = { // Adds or sets a variable in the command environment. This does not affect the -// current process environment. The 'key' must be a valid environment variable -// name per POSIX definition 3.235. This includes underscores and alphanumeric -// ASCII characters, and cannot begin with a number. +// current process environment. The key may not contain '=' or '\0'. export fn setenv(cmd: *command, key: str, value: str) (void | errors::invalid) = { unsetenv(cmd, key)?; append(cmd.env, strings::join("=", key, value));