1
0
mirror of https://github.com/nix-community/home-manager synced 2024-06-02 04:53:33 +02:00

lib.gvariant: escape newlines in strings

See #2096
This commit is contained in:
Robert Helgesson 2021-08-11 23:30:00 +02:00
parent c049a09d1a
commit 604561ba9a
No known key found for this signature in database
GPG Key ID: 36BDAA14C2797E89
2 changed files with 9 additions and 4 deletions

View File

@ -122,8 +122,9 @@ in rec {
};
mkString = v:
mkPrimitive type.string v // {
__toString = self: "'${escape [ "'" "\\" ] self.value}'";
let sanitize = s: replaceStrings [ "\n" ] [ "\\n" ] (escape [ "'" "\\" ] s);
in mkPrimitive type.string v // {
__toString = self: "'${sanitize self.value}'";
};
mkObjectpath = v:

View File

@ -26,7 +26,11 @@ in {
{ string = "foo"; }
{ string = "foo"; }
{ escapedString = "' \\"; }
{
escapedString = ''
'\
'';
}
{ tuple = mkTuple [ 1 [ "foo" ] ]; }
@ -47,7 +51,7 @@ in {
bool = true
emptyArray1 = @as []
emptyArray2 = @as []
escapedString = '\' \\'
escapedString = '\'\\\n'
float = 3.140000
int = 42
list = @as ['one','two']