canonical-json 0.6.0.0 → 0.6.0.1
raw patch · 5 files changed
+59/−11 lines, 5 filesdep ~QuickCheckdep ~aesondep ~basePVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: QuickCheck, aeson, base, bytestring, containers, deepseq
API changes (from Hackage documentation)
- Text.JSON.Canonical.Types: instance Data.Bits.Bits Text.JSON.Canonical.Types.Int54
- Text.JSON.Canonical.Types: instance Data.Bits.FiniteBits Text.JSON.Canonical.Types.Int54
- Text.JSON.Canonical.Types: instance GHC.Arr.Ix Text.JSON.Canonical.Types.Int54
+ Text.JSON.Canonical.Types: instance GHC.Bits.Bits Text.JSON.Canonical.Types.Int54
+ Text.JSON.Canonical.Types: instance GHC.Bits.FiniteBits Text.JSON.Canonical.Types.Int54
+ Text.JSON.Canonical.Types: instance GHC.Ix.Ix Text.JSON.Canonical.Types.Int54
Files
- ChangeLog.md +10/−0
- Text/JSON/Canonical/Parse.hs +1/−1
- Text/JSON/Canonical/Types.hs +1/−1
- canonical-json.cabal +4/−4
- tests/TestSuite.hs +43/−5
ChangeLog.md view
@@ -1,5 +1,15 @@ # Revision history for canonical-json +## 0.6.0.1 2022-09-19++* Support GHC 9.2 and 9.4, and bytestring 0.11.x++* Support recent versions of QuickCheck and Aeson in the tests++* Fix the domain of a property test `prop_aeson_canonical`++* Add CI on github covering GHC versions 8.0, 8.2, 8.4, 8.6, 8.8, 8.10, 9.2+ ## 0.6.0.0 2019-07-31 * Introduced JSString type rather than using String, for improved memory use.
Text/JSON/Canonical/Parse.hs view
@@ -232,7 +232,7 @@ manyN :: Int -> Parser a -> Parser [a] manyN 0 _ = pure []-manyN n p = ((:) <$> p <*> manyN (n-1) p)+manyN n p = ((:) <$> p <*> manyN (n - 1) p) <|> pure [] ------------------------------------------------------------------------------
Text/JSON/Canonical/Types.hs view
@@ -26,7 +26,7 @@ #if !MIN_VERSION_base(4,8,0) import Data.Monoid (Monoid) #endif-#if MIN_VERSION_base(4,9,0)+#if (MIN_VERSION_base(4,9,0) && !MIN_VERSION_base(4,13,0)) import Data.Semigroup (Semigroup) #endif import Data.Typeable (Typeable)
canonical-json.cabal view
@@ -1,5 +1,5 @@ name: canonical-json-version: 0.6.0.0+version: 0.6.0.1 synopsis: Canonical JSON for signing and hashing JSON values description: An implementation of Canonical JSON. .@@ -41,7 +41,7 @@ MultiParamTypeClasses, FlexibleInstances, ScopedTypeVariables, OverlappingInstances build-depends: base >= 4.5 && < 5,- bytestring >= 0.10.4 && < 0.11,+ bytestring >= 0.10.4 && < 0.12, containers >= 0.4 && < 0.7, deepseq >= 1.2 && < 1.5, parsec >= 3.1 && < 3.2,@@ -57,10 +57,10 @@ bytestring, canonical-json, containers,- aeson == 1.4.*,+ aeson >= 1.4 && < 2.2, vector, unordered-containers,- QuickCheck >= 2.11 && < 2.13,+ QuickCheck >= 2.11 && < 2.16, tasty, tasty-quickcheck default-language: Haskell2010
tests/TestSuite.hs view
@@ -14,10 +14,14 @@ #endif import qualified Data.Aeson as Aeson (Value (..), eitherDecode)+#if MIN_VERSION_aeson(2,0,0)+import qualified Data.Aeson.KeyMap as KeyMap (fromList)+#else+import qualified Data.HashMap.Strict as KeyMap (fromList)+#endif import Data.String (IsString, fromString) import qualified Data.Map as Map import qualified Data.Vector as V (fromList)-import qualified Data.HashMap.Strict as HM (fromList) import Test.QuickCheck import Test.Tasty.QuickCheck (testProperty)@@ -63,7 +67,9 @@ fmap canonicalise (parseCanonicalJSON (BS.pack (prettyCanonicalJSON jsval))) prop_aeson_canonical jsval =- Aeson.eitherDecode (renderCanonicalJSON jsval) == Right (toAeson jsval)+ Aeson.eitherDecode (renderCanonicalJSON jsval') == Right (toAeson jsval')+ where+ jsval' = omitNonPrintableChars jsval prop_toJSON_fromJSON :: (Monad m, ToJSON m a, FromJSON m a, Eq a) => a -> m Bool prop_toJSON_fromJSON x =@@ -117,12 +123,43 @@ toAeson (JSNum n) = Aeson.Number (fromIntegral n) toAeson (JSString s) = Aeson.String (toAesonStr s) toAeson (JSArray xs) = Aeson.Array $ V.fromList [ toAeson x | x <- xs ]-toAeson (JSObject xs) = Aeson.Object $ HM.fromList [ (toAesonStr k, toAeson v)- | (k, v) <- xs ]+toAeson (JSObject xs) = Aeson.Object $ KeyMap.fromList [ (toAesonStr k, toAeson v)+ | (k, v) <- xs ] toAesonStr :: IsString s => JSString -> s toAesonStr = fromString . fromJSString +-- | As discussed in the haddock docs for 'renderCanonicalJSON', Canonical+-- JSON is /not/ a proper subset of RFC 7159.+--+-- So for the property 'prop_aeson_canonical', where we check that everything+-- produced as canoncal JSON can be parsed by Aeson (which we assume correctly+-- implements RFC 7159), we have to tweak things to keep us within the common+-- subset of canoncal JSON and RFC 7159. Specifically, canoncal JSON only+-- escapes \ and ", and does not escape any other non-printable characters.+--+-- So the tweak is to just omit non-printable characters from all strings.+--+omitNonPrintableChars :: JSValue -> JSValue+omitNonPrintableChars = omitJSValue+ where+ omitJSValue v@JSNull = v+ omitJSValue v@(JSBool _) = v+ omitJSValue v@(JSNum _) = v+ omitJSValue (JSString s) = JSString (omitJSString s)+ omitJSValue (JSArray vs) = JSArray [ omitJSValue v | v <- vs]+ omitJSValue (JSObject vs) = JSObject $ omitDupKeys+ [ (omitJSString k, omitJSValue v)+ | (k,v) <- vs ]++ omitDupKeys :: [(JSString, JSValue)] -> [(JSString, JSValue)]+ omitDupKeys = nubBy (\a b -> fst a == fst b)++ omitJSString :: JSString -> JSString+ omitJSString = toJSString+ . filter (\c -> c >= ' ')+ . fromJSString+ instance Arbitrary JSValue where arbitrary = sized $ \sz ->@@ -161,5 +198,6 @@ instance Arbitrary JSString where arbitrary = toJSString . getASCIIString <$> arbitrary- shrink s = [ toJSString s' | s' <- shrink (fromJSString s) ]+ shrink s = [ toJSString s' | s' <- shrink (fromJSString s)+ , all (\c -> c >= ' ') s' ]