From 4c34d78cda926c0d69e18eb1e2fb886c56f48de4 Mon Sep 17 00:00:00 2001 From: Fendor Date: Thu, 8 Jul 2021 15:00:18 +0200 Subject: [PATCH] Add standard conform JSON Escaping Reference: RFC 8259, "7. Strings", https://tools.ietf.org/html/rfc8259#section-7 --- Cabal/src/Distribution/Utils/Json.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Cabal/src/Distribution/Utils/Json.hs b/Cabal/src/Distribution/Utils/Json.hs index 3d51b827075..cef32f04d6d 100644 --- a/Cabal/src/Distribution/Utils/Json.hs +++ b/Cabal/src/Distribution/Utils/Json.hs @@ -43,7 +43,11 @@ surround begin end middle = mconcat [ begin , middle , end] escape :: String -> String escape ('\"':xs) = "\\\"" <> escape xs escape ('\\':xs) = "\\\\" <> escape xs -escape ('\'':xs) = "\\\'" <> escape xs +escape ('\b':xs) = "\\b" <> escape xs +escape ('\f':xs) = "\\f" <> escape xs +escape ('\n':xs) = "\\n" <> escape xs +escape ('\r':xs) = "\\r" <> escape xs +escape ('\t':xs) = "\\t" <> escape xs escape (x:xs) = x : escape xs escape [] = mempty