diff --git a/modules/lib/gvariant.nix b/modules/lib/gvariant.nix index 92aa7d983..0704635a2 100644 --- a/modules/lib/gvariant.nix +++ b/modules/lib/gvariant.nix @@ -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: diff --git a/tests/lib/types/gvariant-merge.nix b/tests/lib/types/gvariant-merge.nix index 867534c1f..88440c40a 100644 --- a/tests/lib/types/gvariant-merge.nix +++ b/tests/lib/types/gvariant-merge.nix @@ -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']