Skip to content

Commit 8ef622c

Browse files
committed
Narrow the set of whitespace characters considered valid
This is required by RFC 7159. Once again spotted by JSONTestSuite.
1 parent 9cbf982 commit 8ef622c

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Data/Aeson/Parser/Internal.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import Prelude.Compat
3939
import Control.Applicative ((<|>))
4040
import Control.Monad (void, when)
4141
import Data.Aeson.Types.Internal (IResult(..), JSONPath, Result(..), Value(..))
42-
import Data.Attoparsec.ByteString.Char8 (Parser, char, decimal, endOfInput, isDigit_w8, signed, skipSpace, string)
42+
import Data.Attoparsec.ByteString.Char8 (Parser, char, decimal, endOfInput, isDigit_w8, signed, string)
4343
import Data.Scientific (Scientific)
4444
import Data.Text (Text)
4545
import Data.Vector as Vector (Vector, empty, fromListN, reverse)
@@ -295,6 +295,12 @@ jsonEOF = json <* skipSpace <* endOfInput
295295
jsonEOF' :: Parser Value
296296
jsonEOF' = json' <* skipSpace <* endOfInput
297297

298+
-- | The only valid whitespace in a JSON document is space, newline,
299+
-- carriage return, and tab.
300+
skipSpace :: Parser ()
301+
skipSpace = A.skipWhile $ \w -> w == 0x20 || w == 0x0a || w == 0x0d || w == 0x09
302+
{-# INLINE skipSpace #-}
303+
298304
------------------ Copy-pasted and adapted from attoparsec ------------------
299305

300306
-- A strict pair

tests/UnitTests.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,6 @@ _blacklist = HashSet.fromList [
670670
, "n_string_unescaped_crtl_char.json"
671671
, "n_string_unescaped_newline.json"
672672
, "n_string_unescaped_tab.json"
673-
, "n_structure_whitespace_formfeed.json"
674673
, "string_1_escaped_invalid_codepoint.json"
675674
, "string_1_invalid_codepoint.json"
676675
, "string_1_invalid_codepoints.json"

0 commit comments

Comments
 (0)