Commit 84d7d946 authored by Steffen Michels's avatar Steffen Michels

Merge branch '69-json-and-utf-8' into 'master'

Don't let Text.GenJSON mess up UTF-8 strings

Closes #69

See merge request !262
parents f4ef279a 11e4d468
Pipeline #27673 passed with stage
in 3 minutes and 3 seconds
...@@ -24,7 +24,7 @@ from Data.GenEq import generic gEq ...@@ -24,7 +24,7 @@ from Data.GenEq import generic gEq
| JSONBool !Bool | JSONBool !Bool
| JSONInt !Int | JSONInt !Int
| JSONReal !Real | JSONReal !Real
| JSONString !String | JSONString !String //* Only control characters and '"' will be escaped
| JSONArray ![JSONNode] | JSONArray ![JSONNode]
| JSONObject ![(String,JSONNode)] | JSONObject ![(String,JSONNode)]
| JSONRaw !String | JSONRaw !String
......
...@@ -40,16 +40,13 @@ where ...@@ -40,16 +40,13 @@ where
count i s n count i s n
| i < size s | i < size s
#! c = s.[i] #! c = s.[i]
| c == '"' || c == '/' || c == '\b' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || 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 = 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 + 5) //We'll replace the character by '\uXXXX'
= count(i + 1) s n = count(i + 1) s n
= n = n
needsUniEscape :: Char -> Bool
needsUniEscape c = c < ' ' || c >= '\x7f'
//Copy structure to a string //Copy structure to a string
copyNode :: !Int !JSONNode !*{#Char} -> *(!Int, !*{#Char}) copyNode :: !Int !JSONNode !*{#Char} -> *(!Int, !*{#Char})
copyNode start (JSONNull) buffer = (start + 4, copyChars start 4 "null" buffer) copyNode start (JSONNull) buffer = (start + 4, copyChars start 4 "null" buffer)
...@@ -119,11 +116,11 @@ copyAndEscapeChars soffset doffset num src dst ...@@ -119,11 +116,11 @@ copyAndEscapeChars soffset doffset num src dst
| num > 0 | num > 0
#! c = src.[soffset] #! c = src.[soffset]
//Check for special characters //Check for special characters
| c == '"' || c == '/' || c == '\b' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\\' | c == '"' || c == '\b' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\\'
#! dst & [doffset] = '\\' #! dst & [doffset] = '\\'
#! dst & [doffset + 1] = charOf c #! dst & [doffset + 1] = charOf c
= copyAndEscapeChars (soffset + 1) (doffset + 2) (num - 1) src dst = copyAndEscapeChars (soffset + 1) (doffset + 2) (num - 1) src dst
| needsUniEscape c | c < ' '
#! cint = toInt c #! cint = toInt c
#! dst & [doffset] = '\\' #! dst & [doffset] = '\\'
#! dst & [doffset + 1] = 'u' #! dst & [doffset + 1] = 'u'
...@@ -139,7 +136,6 @@ copyAndEscapeChars soffset doffset num src dst ...@@ -139,7 +136,6 @@ copyAndEscapeChars soffset doffset num src dst
= dst = dst
where where
charOf '"' = '"' charOf '"' = '"'
charOf '/' = '/'
charOf '\b' = 'b' charOf '\b' = 'b'
charOf '\f' = 'f' charOf '\f' = 'f'
charOf '\n' = 'n' charOf '\n' = 'n'
......
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