Skip to content

Commit

Permalink
Add standard conform JSON Escaping
Browse files Browse the repository at this point in the history
Reference: RFC 8259, "7. Strings", https://tools.ietf.org/html/rfc8259#section-7
  • Loading branch information
fendor committed Aug 15, 2021
1 parent 2e6d0db commit 3abcee5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Cabal/src/Distribution/Utils/Json.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 3abcee5

Please sign in to comment.