lib.generators.toGitINI: escape string values in configuration
This should handle the special characters that typically occur.
Upstreaming of 642d9ffe24
This commit is contained in:
@@ -189,10 +189,10 @@ rec {
|
|||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
*> [url "ssh://git@github.com/"]
|
*> [url "ssh://git@github.com/"]
|
||||||
*> insteadOf = https://github.com/
|
*> insteadOf = "https://github.com"
|
||||||
*>
|
*>
|
||||||
*> [user]
|
*> [user]
|
||||||
*> name = edolstra
|
*> name = "edolstra"
|
||||||
*/
|
*/
|
||||||
toGitINI = attrs:
|
toGitINI = attrs:
|
||||||
with builtins;
|
with builtins;
|
||||||
@@ -209,9 +209,17 @@ rec {
|
|||||||
else
|
else
|
||||||
''${section} "${subsection}"'';
|
''${section} "${subsection}"'';
|
||||||
|
|
||||||
|
mkValueString = v:
|
||||||
|
let
|
||||||
|
escapedV = ''
|
||||||
|
"${
|
||||||
|
replaceStrings [ "\n" " " ''"'' "\\" ] [ "\\n" "\\t" ''\"'' "\\\\" ] v
|
||||||
|
}"'';
|
||||||
|
in mkValueStringDefault { } (if isString v then escapedV else v);
|
||||||
|
|
||||||
# generation for multiple ini values
|
# generation for multiple ini values
|
||||||
mkKeyValue = k: v:
|
mkKeyValue = k: v:
|
||||||
let mkKeyValue = mkKeyValueDefault { } " = " k;
|
let mkKeyValue = mkKeyValueDefault { inherit mkValueString; } " = " k;
|
||||||
in concatStringsSep "\n" (map (kv: "\t" + mkKeyValue kv) (lib.toList v));
|
in concatStringsSep "\n" (map (kv: "\t" + mkKeyValue kv) (lib.toList v));
|
||||||
|
|
||||||
# converts { a.b.c = 5; } to { "a.b".c = 5; } for toINI
|
# converts { a.b.c = 5; } to { "a.b".c = 5; } for toINI
|
||||||
|
|||||||
Reference in New Issue
Block a user