on master help sign in
Don't crash on null input
commitae23fe9b7dce1cd83eabd0307ec65f5dca7f674b authorMichael Snoyman <michael@snoyman.com> dateWed 11 Jul 2012, 08:08 (14 years ago) parent881be91
2 files changed+6
Text/Libyaml.hs+1 test/main.hs+5
Text/Libyaml.hs+1
@@ -453,6 +453,7 @@ newtype ToEventRawException = ToEventRawException CInt
453453instance Exception ToEventRawException
454454
455455decode :: MonadResource m => B.ByteString -> GSource m Event
456+decode bs | B8.null bs = return ()
456457decode bs =
457458 bracketP alloc cleanup (runParser . fst)
458459 where
test/main.hs+5
@@ -61,6 +61,8 @@ main = hspecX $ do
6161 it "parses when all lowercase" caseLowercaseBool
6262 it "parses when all uppercase" caseUppercaseBool
6363 it "parses when titlecase" caseTitlecaseBool
64+ describe "empty input" $ do
65+ it "doesn't crash" caseEmptyInput
6466
6567counter :: Monad m => (Y.Event -> Bool) -> C.Sink Y.Event m Int
6668counter pred' =
@@ -322,3 +324,6 @@ caseLowercaseBool, caseUppercaseBool, caseTitlecaseBool :: Assertion
322324caseLowercaseBool = D.decode "foo: off\nbar: y\nbaz: true" @?= obj
323325caseUppercaseBool = D.decode "foo: FALSE\nbar: Y\nbaz: ON" @?= obj
324326caseTitlecaseBool = D.decode "foo: No\nbar: Yes\nbaz: True" @?= obj
327+
328+caseEmptyInput :: Assertion
329+caseEmptyInput = D.decode B8.empty @?= (Nothing :: Maybe D.Value)