home: environment-variables: Fix escaping.

* gnu/home/services.scm (environment-variable-shell-definitions): Fix
escaping.
* tests/guix-home.sh: Add STRING_WITH_ESCAPES environment variable and test
its value.

Reported-by: elevnkb
This commit is contained in:
Andrew Tropin 2023-01-09 12:22:56 +04:00
parent 2acce55a00
commit 35ecbb418c
No known key found for this signature in database
GPG key ID: 2208D20958C1DEB0
2 changed files with 6 additions and 3 deletions

View file

@ -192,7 +192,7 @@ (define (environment-variable-shell-definitions variables)
(list->string (string-fold-right
(lambda (chr lst)
(if (memq chr quoted-chars)
(append (list chr #\\) lst)
(append (list #\\ chr) lst)
(cons chr lst)))
'()
value))))

View file

@ -84,8 +84,9 @@ trap 'chmod -Rf +w "$test_directory"; rm -rf "$test_directory"' EXIT
home-environment-variables-service-type
`(("TODAY" . "26 messidor")
("SHELL" . ,(file-append bash "/bin/bash"))
("BUILDHOSTTIME" . ,#~(strftime "%c"
("BUILDHOST_TIME" . ,#~(strftime "%c"
(localtime (current-time))))
("STRING_WITH_ESCAPES" . "chars: \" /\\")
("LITERAL" . ,(literal-string "${abc}"))))
(simple-service 'home-bash-service-extension-test
@ -156,6 +157,8 @@ EOF
( . "${HOME}/.guix-home/setup-environment"; test "$TODAY" = "26 messidor" )
( . "${HOME}/.guix-home/setup-environment"; test "$LITERAL" = '${abc}' )
( . "${HOME}/.guix-home/setup-environment";
test "$STRING_WITH_ESCAPES" = "chars: \" /\\")
( . "${HOME}/.guix-home/setup-environment";
echo "$SHELL" | grep "/gnu/store/.*/bin/bash" )