Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions aeson.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ test-suite aeson-tests
Regression.Issue571
Regression.Issue687
Regression.Issue967
Regression.Issue1138
RFC8785
SerializationFormatSpec
Types
Expand Down
4 changes: 3 additions & 1 deletion src/Data/Aeson/Decoding/ByteString.hs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ scanStringLiteral ok err bs0 = go 0 bs0 where
Right t -> ok t (BS.drop (n + 1) bs0)
Left e -> err (show e)
Just (92, bs') -> goSlash (n + 1) bs'
Just (_, bs') -> goEsc (n + 1) bs'
Just (w8, bs')
| w8 < 0x20 -> errCC
| otherwise -> goEsc (n + 1) bs'

goSlash :: Int -> ByteString -> r
goSlash !n !bs = case BS.uncons bs of
Expand Down
4 changes: 3 additions & 1 deletion src/Data/Aeson/Decoding/ByteString/Lazy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ scanStringLiteral ok err bs0 = go 0 bs0 where
Right t -> ok t (lbsDrop (n + 1) bs0)
Left e -> err (show e)
Just (92, bs') -> goSlash (n + 1) bs'
Just (_, bs') -> goEsc (n + 1) bs'
Just (w8, bs')
| w8 < 0x20 -> errCC
| otherwise -> goEsc (n + 1) bs'

goSlash :: Int -> ByteString -> r
goSlash !n !bs = case LBS.uncons bs of
Expand Down
4 changes: 3 additions & 1 deletion src/Data/Aeson/Decoding/Text.hs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ scanStringLiteral ok err bs0 = go 0 bs0 where
Right t -> ok t (unsafeDropPoints (n + 1) bs0)
Left e -> err (show e)
Just (92, bs') -> goSlash (n + 1) bs'
Just (_, bs') -> goEsc (n + 1) bs'
Just (w8, bs')
| w8 < 0x20 -> errCC
| otherwise -> goEsc (n + 1) bs'

goSlash :: Int -> Text -> r
goSlash !n !bs = case unconsPoint bs of
Expand Down
23 changes: 23 additions & 0 deletions tests/Regression/Issue1138.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{-# LANGUAGE OverloadedStrings #-}
module Regression.Issue1138 (issue1138) where

import Test.Tasty (TestTree, testGroup)
import Test.Tasty.HUnit (testCase, assertFailure)

import Data.Aeson

assertDecodeFailure :: Either String Value -> IO ()
assertDecodeFailure (Right v) = assertFailure $ "Unexpected success: " ++ show v
assertDecodeFailure (Left _) = return ()

issue1138 :: TestTree
issue1138 = testGroup "Issue #1138" $ map (testCase "-")
[ assertDecodeFailure $ eitherDecode "\"\t\""
, assertDecodeFailure $ eitherDecode "\"\\\\\t\""

, assertDecodeFailure $ eitherDecodeStrict "\"\t\""
, assertDecodeFailure $ eitherDecodeStrict "\"\\\\\t\""

, assertDecodeFailure $ eitherDecodeStrictText "\"\t\""
, assertDecodeFailure $ eitherDecodeStrictText "\"\\\\\t\""
]
2 changes: 2 additions & 0 deletions tests/UnitTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import Regression.Issue351
import Regression.Issue571
import Regression.Issue687
import Regression.Issue967
import Regression.Issue1138
import UnitTests.OmitNothingFieldsNote
import UnitTests.FromJSONKey
import UnitTests.Hashable
Expand Down Expand Up @@ -568,6 +569,7 @@ tests = testGroup "unit" [
, issue571
, issue687
, issue967
, issue1138
, keyMapInsertWithTests
, omitNothingFieldsNoteTests
, noThunksTests
Expand Down