Skip to content

Commit cf8f1da

Browse files
committed
Fix tests, based on the patch by @ezzieyguywuf in #247 and advice from @Bodigrim
1 parent eae375f commit cf8f1da

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

hackage-security/hackage-security.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ test-suite TestSuite
255255
bytestring,
256256
network-uri,
257257
tar,
258+
text,
258259
time,
259260
zlib
260261

hackage-security/tests/TestSuite/JSON.hs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import Data.String (fromString)
2323
import qualified Data.Vector as V
2424
import qualified Data.HashMap.Strict as HM
2525

26+
-- text
27+
import qualified Data.Text as Text
28+
2629
prop_aeson_canonical, prop_roundtrip_canonical, prop_roundtrip_pretty, prop_canonical_pretty
2730
:: JSValue -> Bool
2831

@@ -48,16 +51,19 @@ canonicalise (JSArray vs) = JSArray [ canonicalise v | v <- vs]
4851
canonicalise (JSObject vs) = JSObject [ (k, canonicalise v)
4952
| (k,v) <- sortBy (compare `on` fst) vs ]
5053

54+
sanitizeString :: String -> String
55+
sanitizeString s = Text.unpack (Text.replace (Text.pack "\\") (Text.pack "\\\\") (Text.pack (show s)))
56+
5157
instance Arbitrary JSValue where
5258
arbitrary =
5359
sized $ \sz ->
5460
frequency
5561
[ (1, pure JSNull)
5662
, (1, JSBool <$> arbitrary)
5763
, (2, JSNum <$> arbitrary)
58-
, (2, JSString . getASCIIString <$> arbitrary)
64+
, (2, JSString . sanitizeString . getASCIIString <$> arbitrary)
5965
, (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)
6167
]
6268
where
6369
noDupFields = nubBy (\(x,_) (y,_) -> x==y)

0 commit comments

Comments
 (0)