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: Antlers
Subject: [bug#54846] [PATCH] gnu: linux: Escape the values of string-type kconfig options
Date: Thu, 28 Apr 2022 20:18:04 +0000 (UTC)

Yeah, sorry for the silence, there's been a lot going on and being able to use 
strings in the first place is a comportable baseline of functionality- I don't 
feel that one should implement implicit escaping of a field until confident 
that all the corner cases are handled, and think that there are some subtle 
warts left. Haven't had that time iron those out, but I'll be glad to polish 
the details and can follow up within about a week once I've addressed my 
remaining cornerns about correctness. Thanks for bearing with me I fumble my 
way through the conventions of the mailing list and formatting, nitpicks are 
what I'm here for c:

I think transform-string is a gem for the task, the inputs are flexible and the 
author specifically cites better performance than string-fold in the (ice-9 
texinfo) source, but I appreciate your point and can happily specialize it 
in-line.

----------------------------------------

Apr 28, 2022 5:16:46 AM Ludovic Courtès <ludo@gnu.org>:

> Hi antlers,
>
> Did you have a chance to look into it?
>
> TIA,
> Ludo’.
>
> Ludovic Courtès <ludo@gnu.org> skribis:
>
>> 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]