mirror of
https://github.com/QB64-Phoenix-Edition/QB64pe.git
synced 2024-09-19 23:44:46 +00:00
Allow setting environment variables with space in values
This commit is contained in:
parent
ac2777fd20
commit
1d5a8d79b8
3 changed files with 60 additions and 6 deletions
|
@ -70,13 +70,11 @@ void sub_environ(qbs *str) {
|
||||||
buf = (char *)malloc(str->len + 1);
|
buf = (char *)malloc(str->len + 1);
|
||||||
buf[str->len] = '\0';
|
buf[str->len] = '\0';
|
||||||
memcpy(buf, str->chr, str->len);
|
memcpy(buf, str->chr, str->len);
|
||||||
// Name and value may be separated by = or space
|
// Name and value may be separated by = or space, whichever appears first.
|
||||||
separator = strchr(buf, ' ');
|
separator = buf + strcspn(buf, " =");
|
||||||
if (!separator) {
|
if (*separator == '\0') {
|
||||||
separator = strchr(buf, '=');
|
|
||||||
}
|
|
||||||
if (!separator) {
|
|
||||||
// It is an error is there is no separator
|
// It is an error is there is no separator
|
||||||
|
free(buf);
|
||||||
error(5);
|
error(5);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
48
tests/compile_tests/environ/set_environ.bas
Normal file
48
tests/compile_tests/environ/set_environ.bas
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
$CONSOLE:ONLY
|
||||||
|
ON ERROR GOTO ehandler
|
||||||
|
|
||||||
|
'Test setting with =
|
||||||
|
ENVIRON "FOO=BAR"
|
||||||
|
PRINT ENVIRON$("FOO")
|
||||||
|
|
||||||
|
|
||||||
|
'Test settings with space
|
||||||
|
ENVIRON "VAR VAL"
|
||||||
|
PRINT ENVIRON$("VAR")
|
||||||
|
|
||||||
|
|
||||||
|
'Test setting value with spaces with = separator
|
||||||
|
ENVIRON "ABC=DEF GHI"
|
||||||
|
PRINT ENVIRON$("ABC")
|
||||||
|
|
||||||
|
|
||||||
|
'Test setting value with spaces with space separator
|
||||||
|
ENVIRON "JKL MNO PQR"
|
||||||
|
PRINT ENVIRON$("JKL")
|
||||||
|
|
||||||
|
|
||||||
|
'Test overwriting existing
|
||||||
|
ENVIRON "X=XY"
|
||||||
|
ENVIRON "X=ZZZ"
|
||||||
|
PRINT ENVIRON$("X")
|
||||||
|
|
||||||
|
|
||||||
|
'Test unset variable with = separator
|
||||||
|
ENVIRON "NAME=LUKE"
|
||||||
|
ENVIRON "NAME="
|
||||||
|
PRINT "["; ENVIRON$("NAME"); "]"
|
||||||
|
|
||||||
|
|
||||||
|
'Test unset variable with space separator
|
||||||
|
ENVIRON "TEXT BOO"
|
||||||
|
ENVIRON "TEXT "
|
||||||
|
PRINT "["; ENVIRON$("TEXT"); "]"
|
||||||
|
|
||||||
|
'Test no separator
|
||||||
|
ENVIRON "NOSEP"
|
||||||
|
|
||||||
|
SYSTEM
|
||||||
|
|
||||||
|
ehandler:
|
||||||
|
print "Error"; ERR; "line"; _ERRORLINE
|
||||||
|
RESUME NEXT
|
8
tests/compile_tests/environ/set_environ.output
Normal file
8
tests/compile_tests/environ/set_environ.output
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
BAR
|
||||||
|
VAL
|
||||||
|
DEF GHI
|
||||||
|
MNO PQR
|
||||||
|
ZZZ
|
||||||
|
[]
|
||||||
|
[]
|
||||||
|
Error 5 line 42
|
Loading…
Reference in a new issue