@@ -23,6 +23,9 @@ import Data.String (fromString)
23
23
import qualified Data.Vector as V
24
24
import qualified Data.HashMap.Strict as HM
25
25
26
+ -- text
27
+ import qualified Data.Text as Text
28
+
26
29
prop_aeson_canonical, prop_roundtrip_canonical, prop_roundtrip_pretty, prop_canonical_pretty
27
30
:: JSValue -> Bool
28
31
@@ -48,16 +51,19 @@ canonicalise (JSArray vs) = JSArray [ canonicalise v | v <- vs]
48
51
canonicalise (JSObject vs) = JSObject [ (k, canonicalise v)
49
52
| (k,v) <- sortBy (compare `on` fst ) vs ]
50
53
54
+ sanitizeString :: String -> String
55
+ sanitizeString s = Text. unpack (Text. replace (Text. pack " \\ " ) (Text. pack " \\\\ " ) (Text. pack (show s)))
56
+
51
57
instance Arbitrary JSValue where
52
58
arbitrary =
53
59
sized $ \ sz ->
54
60
frequency
55
61
[ (1 , pure JSNull )
56
62
, (1 , JSBool <$> arbitrary)
57
63
, (2 , JSNum <$> arbitrary)
58
- , (2 , JSString . getASCIIString <$> arbitrary)
64
+ , (2 , JSString . sanitizeString . getASCIIString <$> arbitrary)
59
65
, (3 , JSArray <$> resize (sz `div` 2 ) arbitrary)
60
- , (3 , JSObject . mapFirst getASCIIString . noDupFields <$> resize (sz `div` 2 ) arbitrary)
66
+ , (3 , JSObject . mapFirst (sanitizeString . getASCIIString) . noDupFields <$> resize (sz `div` 2 ) arbitrary)
61
67
]
62
68
where
63
69
noDupFields = nubBy (\ (x,_) (y,_) -> x== y)
0 commit comments