guix-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug#54846] [PATCH] gnu: linux: Escape the values of string-type kconfig


From: Ludovic Courtès
Subject: [bug#54846] [PATCH] gnu: linux: Escape the values of string-type kconfig options
Date: Tue, 12 Apr 2022 23:39:07 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)

Hi,

antlers <autumnalantlers@gmail.com> skribis:

>  * gnu/packages/linux.scm (config->string): add escape-string
>
> Handles characters within the set
> (char-set-intersection char-set:ascii char-set:printing), removing
> those which are known to be unsupported.

[...]

>  (define (config->string options)
> +  (define (escape-string str)
> +    "Returns STR with the escapes necessary to be read as a string-type
> +    option's value. Handles characters within the set (char-set-intersection
> +    char-set:ascii char-set:printing), removing those which are known to be
> +    unsupported."

Nitpick: You can turn the docstring into a comment since the docstring
wouldn’t be accessible anyway.

> +    (fold (match-lambda* (((match? fmt) str)
> +                       (transform-string str match?
> +                                         (cut format #f fmt <>))))

Please avoid tabs.

‘transform-string’ is from (texinfo string-utils), which is not imported
here.  IMO, we’d rather avoid depending on this module since it’s really
designed for the Texinfo machinery.

> +       str
> +       `((#\# "") ; No known way to escape # characters.
> +         (#\$ "$~a")
> +         ("\"\\'`" "\\~a")
> +         (";:()#" "\\\\~a")
> +         ("|" "\\\\\\~a")
> +         ;; No support for tabs, newlines, etc.
> +         (,(char-set->string (ucs-range->char-set 9 14)) ""))))

I wonder if this should be implemented in terms of ‘string-fold’
instead:

  (string-concatenate-reverse
    (string-fold (lambda (chr result)
                   (match chr
                     (#\# (cons "" result))
                     ;; …
                     (_ (cons (string chr) result))))
                 '()
                 str))

Thoughts?

Thanks,
Ludo’.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]