Skip to content
This repository was archived by the owner on May 2, 2020. It is now read-only.

Commit 75288f0

Browse files
committed
Workaround for bug in pcre-light
1 parent d84d693 commit 75288f0

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/JSONSchema/Validator/Draft4/String.hs

+3-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ patternVal :: PatternValidator -> Text -> Maybe PatternInvalid
6969
patternVal a@(PatternValidator t) x =
7070
case RE.compileM (encodeUtf8 t) mempty of
7171
Left _ -> Just PatternNotRegex
72-
Right re -> if x RE.=~ re
72+
Right re -> if input RE.=~ re
7373
then Nothing
7474
else Just (PatternInvalid a x)
75+
where
76+
input = T.unpack x -- workaround for a bug in pcre-light

test/JSONSchema/Validator/Draft4/StringSpec.hs

+8
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,11 @@ spec = do
1515

1616
it "rejects other strings" $ do
1717
maxLengthVal (MaxLength 0) "foo" `shouldBe` Just (MaxLengthInvalid (MaxLength 0) "foo")
18+
19+
describe "patternVal" $ do
20+
it "matches a substring" $ do
21+
patternVal (PatternValidator "baz") "foo bar baz" `shouldBe` Nothing
22+
23+
context "with .*" $ do
24+
it "matches the empty string (test for workaround for a bug in pcre-light)" $ do
25+
patternVal (PatternValidator ".*") "" `shouldBe` Nothing

0 commit comments

Comments
 (0)