bug#63048: [Home] Shell alias values are not properly quoted

2023-07-11 Thread Ludovic Courtès
Ludovic Courtès  skribis:

> From: Ludovic Courtès 
>
> Fixes .
> Reported by Ekaitz Zarraga .
>
> * gnu/home/services.scm (with-shell-quotation-bindings): New procedure.
> (environment-variable-shell-definitions): Use it instead of inline copy.
> * gnu/home/services/shells.scm (bash-serialize-aliases): Use it.  Add
> clause for 'literal-string?'.
> * tests/guix-home.sh: Add 'aliases' to 'home-bash-extension' and test it.

Pushed as 7d9fdfb19d17dc99a4cf2548942c4f8ae7433572!

Ludo'.





bug#63048: [Home] Shell alias values are not properly quoted

2023-04-24 Thread Ekaitz Zarraga


I made something like this instead of reusing the code you suggested, Ludo.
But it doesn't work. I don't really know why:

diff --git a/guix/scripts/home/import.scm b/guix/scripts/home/import.scm
index fd263c0699..2d7a7abbf2 100644
--- a/guix/scripts/home/import.scm
+++ b/guix/scripts/home/import.scm
@@ -64,12 +64,23 @@ (define (destination-append path)
   (define alias-rx
 (make-regexp "^alias ([^=]+)=[\"'](.+)[\"']$"))
 
+  (define (quote-style line)
+(cond
+  ((string-match "^alias ([^=]+)=[\"].*$" line) 'double)
+  ((string-match "^alias ([^=]+)=['].*$" line)  'single)))
+
   (define (bash-alias->pair line)
 (match (regexp-exec alias-rx line)
   (#f #f)
   (matched
`(,(match:substring matched 1) . ,(match:substring matched 2)
 
+  (define (escape-alias-body quote-style body)
+(if (eq? quote-style 'single)
+  (let* ((escaped-dquotes (string-replace-substring  body "\"" "\\\"")))
+(string-replace-substring escaped-dquotes "\\'" "'"))
+  body))
+
   (define (parse-aliases input)
 (let loop ((result '()))
   (match (read-line input)
@@ -78,7 +89,7 @@ (define (parse-aliases input)
 (line
  (match (bash-alias->pair line)
(#f(loop result))
-   (alias (loop (cons alias result
+   (alias (loop (cons alias (escape-alias-body (quote-style line) 
result)
 
   (let ((rc (destination-append ".bashrc"))
 (profile (destination-append ".bash_profile"))






bug#63048: [Home] Shell alias values are not properly quoted

2023-04-24 Thread Ekaitz Zarraga
As an extra note:

The problem I encountered was when the alias was defined using single quote 
marks:

alias ls='ls blabla "problem"'

this is parsed to:

("ls" . "blabla \"problem\"")

Which is written as:

alias ls="blabla "problem""

Which is wrong.

So the problem relies on the fact that the quotations marks have been changed 
from ' to " and the escaping have not been adjusted accordingly.

:)





bug#63048: [Home] Shell alias values are not properly quoted

2023-04-24 Thread Ludovic Courtès
Hi!

As Ekaitz reported on Mastodon, shell alias values are not properly
quoted, which causes problem when an alias value contains double-quotes
for instance:

--8<---cut here---start->8---
(define (bash-serialize-aliases field-name val)
  #~(string-append
 #$@(map
 (match-lambda
   ((key . #f)
"")
   ((key . #t)
#~(string-append "alias " #$key "\n"))
   ((key . value)
#~(string-append "alias " #$key "=\"" #$value "\"\n")))
 val)))
--8<---cut here---end--->8---

The solution is to borrow and factorize the code of
‘environment-variable-shell-definitions’, which does it right.

Ludo’.