git.iko.soy/typeable/hjsonschema
on master help sign in
Switch from a POSIX to Perl based regex lib.

This should make hjsonschema regexes behave more similarly to ECMAScript regexes, which the spec requires.

commitcd19d797eea968107a980b42bc1422b8c7c1ca07 authorIan Grant Jeffries <ian@housejeffries.com> dateFri 29 Apr 2016, 16:44 (10 years ago) parent4db6441
4 files changed+16−10
README.md+1−1 hjsonschema.cabal+1−1 src/Data/Validator/Draft4/Object/Properties.hs+7−4 src/Data/Validator/Draft4/String.hs+7−4
README.md+1−1
@@ -42,7 +42,7 @@ Will start an HTTP server temporarily on port 1234:
4242
4343## Bad Parts
4444
45−+ Uses the [regexpr](https://hackage.haskell.org/package/regexpr-0.5.4) regular expression library for the "pattern" validator. It should use a library based on the ECMA 262 regex dialect, which the [spec](http://json-schema.org/latest/json-schema-validation.html#anchor33) requires.
45++ Uses the [pcre-heavy](https://hackage.haskell.org/package/pcre-heavy) regular expression library for the "pattern" validator. It should use a library based on the ECMA 262 regex dialect, which the [spec](http://json-schema.org/latest/json-schema-validation.html#anchor33) requires.
4646
4747## Notes
4848
hjsonschema.cabal+1−1
@@ -50,8 +50,8 @@ library
5050 , hjsonpointer >= 0.3 && < 0.4
5151 , http-client >= 0.4.9 && < 0.5
5252 , http-types >= 0.8 && < 0.10
53+ , pcre-heavy >= 1.0 && < 1.1
5354 , QuickCheck >= 2.8.1 && < 2.9
54− , regexpr >= 0.5 && < 0.6
5555 , scientific >= 0.3 && < 0.4
5656 , semigroups >= 0.18.0 && < 0.19
5757 , unordered-containers >= 0.2 && < 0.3
src/Data/Validator/Draft4/Object/Properties.hs+7−4
@@ -7,7 +7,8 @@ import Data.Aeson
77import qualified Data.Aeson.Pointer as P
88import qualified Data.HashMap.Strict as H
99import qualified Data.Text as T
10−import Text.RegexPR
10+import Data.Text.Encoding (encodeUtf8)
11+import qualified Text.Regex.PCRE.Heavy as RE
1112
1213import Data.Validator.Failure
1314import Import
@@ -126,9 +127,11 @@ patternAndUnmatched f patPropertiesHm x =
126127 -> schema
127128 -> [schema]
128129 checkKey k acc r subSchema =
129− case matchRegexPR (T.unpack r) (T.unpack k) of
130− Nothing -> acc
131− Just _ -> pure subSchema <> acc
130+ case RE.compileM (encodeUtf8 r) mempty of
131+ Left _ -> acc
132+ Right re -> if k RE.=~ re
133+ then pure subSchema <> acc
134+ else acc
132135
133136 runVals
134137 :: [Failure err]
src/Data/Validator/Draft4/String.hs+7−4
@@ -3,7 +3,8 @@ module Data.Validator.Draft4.String where
33
44import Data.Aeson
55import qualified Data.Text as T
6−import Text.RegexPR
6+import Data.Text.Encoding (encodeUtf8)
7+import qualified Text.Regex.PCRE.Heavy as RE
78
89import Data.Validator.Failure
910import Import
@@ -24,6 +25,8 @@ minLength n x
2425
2526patternVal :: Text -> Text -> Maybe (Failure ())
2627patternVal t x =
27− case matchRegexPR (T.unpack t) (T.unpack x) of
28− Nothing -> Just (Failure () (toJSON t) mempty)
29− Just _ -> Nothing
28+ case RE.compileM (encodeUtf8 t) mempty of
29+ Left _ -> Just (Failure () (toJSON t) mempty)
30+ Right re -> if x RE.=~ re
31+ then Nothing
32+ else Just (Failure () (toJSON t) mempty)