Merge pull request #250220
lib.generators.toGitINI: escape string values in configuration
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
|
||||||
|
|||||||
@@ -948,6 +948,51 @@ runTests {
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
testToGitINI = {
|
||||||
|
expr = generators.toGitINI {
|
||||||
|
user = {
|
||||||
|
email = "user@example.org";
|
||||||
|
name = "John Doe";
|
||||||
|
signingKey = "00112233445566778899AABBCCDDEEFF";
|
||||||
|
};
|
||||||
|
gpg.program = "path-to-gpg";
|
||||||
|
tag.gpgSign = true;
|
||||||
|
include.path = "~/path/to/config.inc";
|
||||||
|
includeIf."gitdif:~/src/dir".path = "~/path/to/conditional.inc";
|
||||||
|
extra = {
|
||||||
|
boolean = true;
|
||||||
|
integer = 38;
|
||||||
|
name = "value";
|
||||||
|
subsection.value = "test";
|
||||||
|
};};
|
||||||
|
expected = ''
|
||||||
|
[extra]
|
||||||
|
${"\t"}boolean = true
|
||||||
|
${"\t"}integer = 38
|
||||||
|
${"\t"}name = "value"
|
||||||
|
|
||||||
|
[extra "subsection"]
|
||||||
|
${"\t"}value = "test"
|
||||||
|
|
||||||
|
[gpg]
|
||||||
|
${"\t"}program = "path-to-gpg"
|
||||||
|
|
||||||
|
[include]
|
||||||
|
${"\t"}path = "~/path/to/config.inc"
|
||||||
|
|
||||||
|
[includeIf "gitdif:~/src/dir"]
|
||||||
|
${"\t"}path = "~/path/to/conditional.inc"
|
||||||
|
|
||||||
|
[tag]
|
||||||
|
${"\t"}gpgSign = true
|
||||||
|
|
||||||
|
[user]
|
||||||
|
${"\t"}email = "user@example.org"
|
||||||
|
${"\t"}name = "John Doe"
|
||||||
|
${"\t"}signingKey = "00112233445566778899AABBCCDDEEFF"
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
/* right now only invocation check */
|
/* right now only invocation check */
|
||||||
testToJSONSimple =
|
testToJSONSimple =
|
||||||
let val = {
|
let val = {
|
||||||
|
|||||||
Reference in New Issue
Block a user