Verified Commit b6502d17 authored by Camil Staps's avatar Camil Staps 🚀

Resolve #69: don't let Text.GenJSON mess up UTF-8 strings

parent f4ef279a
......@@ -24,7 +24,7 @@ from Data.GenEq import generic gEq
| JSONBool !Bool
| JSONInt !Int
| JSONReal !Real
| JSONString !String
| JSONString !String //* Only control characters and '"' will be escaped
| JSONArray ![JSONNode]
| JSONObject ![(String,JSONNode)]
| JSONRaw !String
......
......@@ -42,14 +42,11 @@ where
#! c = s.[i]
| c == '"' || c == '/' || c == '\b' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\\'
= count (i + 1) s (n + 1) //We'll add a '\' to escape
| needsUniEscape c
| c < ' '
= count (i + 1) s (n + 5) //We'll replace the character by '\uXXXX'
= count(i + 1) s n
= n
needsUniEscape :: Char -> Bool
needsUniEscape c = c < ' ' || c >= '\x7f'
//Copy structure to a string
copyNode :: !Int !JSONNode !*{#Char} -> *(!Int, !*{#Char})
copyNode start (JSONNull) buffer = (start + 4, copyChars start 4 "null" buffer)
......@@ -123,7 +120,7 @@ copyAndEscapeChars soffset doffset num src dst
#! dst & [doffset] = '\\'
#! dst & [doffset + 1] = charOf c
= copyAndEscapeChars (soffset + 1) (doffset + 2) (num - 1) src dst
| needsUniEscape c
| c < ' '
#! cint = toInt c
#! dst & [doffset] = '\\'
#! dst & [doffset + 1] = 'u'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment