on master help sign in
Don't crash on null input
ae23fe9Michael Snoyman
Text/Libyaml.hs+1
@@ -453,6 +453,7 @@ newtype ToEventRawException = ToEventRawException CInt
453instance Exception ToEventRawException
453instance Exception ToEventRawException
454
454
455decode :: MonadResource m => B.ByteString -> GSource m Event
455decode :: MonadResource m => B.ByteString -> GSource m Event
456+decode bs | B8.null bs = return ()
456decode bs =
457decode bs =
457 bracketP alloc cleanup (runParser . fst)
458 bracketP alloc cleanup (runParser . fst)
458 where
459 where
test/main.hs+5
@@ -61,6 +61,8 @@ main = hspecX $ do
61 it "parses when all lowercase" caseLowercaseBool
61 it "parses when all lowercase" caseLowercaseBool
62 it "parses when all uppercase" caseUppercaseBool
62 it "parses when all uppercase" caseUppercaseBool
63 it "parses when titlecase" caseTitlecaseBool
63 it "parses when titlecase" caseTitlecaseBool
64+ describe "empty input" $ do
65+ it "doesn't crash" caseEmptyInput
64
66
65counter :: Monad m => (Y.Event -> Bool) -> C.Sink Y.Event m Int
67counter :: Monad m => (Y.Event -> Bool) -> C.Sink Y.Event m Int
66counter pred' =
68counter pred' =
@@ -322,3 +324,6 @@ caseLowercaseBool, caseUppercaseBool, caseTitlecaseBool :: Assertion
322caseLowercaseBool = D.decode "foo: off\nbar: y\nbaz: true" @?= obj
324caseLowercaseBool = D.decode "foo: off\nbar: y\nbaz: true" @?= obj
323caseUppercaseBool = D.decode "foo: FALSE\nbar: Y\nbaz: ON" @?= obj
325caseUppercaseBool = D.decode "foo: FALSE\nbar: Y\nbaz: ON" @?= obj
324caseTitlecaseBool = D.decode "foo: No\nbar: Yes\nbaz: True" @?= obj
326caseTitlecaseBool = D.decode "foo: No\nbar: Yes\nbaz: True" @?= obj
327+
328+caseEmptyInput :: Assertion
329+caseEmptyInput = D.decode B8.empty @?= (Nothing :: Maybe D.Value)