json2nix: fix string quotation bug

This commit is contained in:
Oystein Kristoffer Tveit 2022-11-28 20:23:03 +01:00
parent d30a1093a3
commit 42758507b6
Signed by: oysteikt
GPG Key ID: 9F2F7D8250F35146
1 changed files with 3 additions and 3 deletions

View File

@ -38,6 +38,6 @@ json2Nix (A.Number n) = T.pack $ show n
json2Nix (A.Bool False) = "false" json2Nix (A.Bool False) = "false"
json2Nix (A.Bool True) = "true" json2Nix (A.Bool True) = "true"
json2Nix A.Null = "null" json2Nix A.Null = "null"
json2Nix (A.String text) = T.concat [sep, text, sep] -- Nixfmt will handle which quotation mark we are using anyway, so we
where -- might as well just escape all "s and use them as string markers.
sep = if "\"" `T.isInfixOf` text then "\'\'" else "\"" json2Nix (A.String text) = T.concat ["\"", T.replace "\"" "\\\"" text, "\""]