Skip to content

Commit 5abf494

Browse files
authored
Merge pull request #769 from phadej/issue-515
Fix #515. Don't accept unescaped control characters
2 parents 80c787d + 00b68be commit 5abf494

File tree

4 files changed

+10
-11
lines changed

4 files changed

+10
-11
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Of course before submitting a PR, the following steps are recommended:
8787

8888
A ghci development experience would be:
8989

90-
1. `cabal new-repl test:tests`
90+
1. `cabal new-repl aeson-tests`
9191
2. `:r` to recompile
9292
3. `Main.main` to run all tests, or `:m Main; :main --pattern Foo` to run specific tests matched by pattern.
9393

Data/Aeson/Parser/Internal.hs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ import Data.Aeson.Types.Internal (IResult(..), JSONPath, Object, Result(..), Val
5555
import Data.Attoparsec.ByteString.Char8 (Parser, char, decimal, endOfInput, isDigit_w8, signed, string)
5656
import Data.Function (fix)
5757
import Data.Functor.Compat (($>))
58-
import Data.Bits (testBit)
5958
import Data.Scientific (Scientific)
6059
import Data.Text (Text)
6160
import qualified Data.Text.Encoding as TE
@@ -320,13 +319,16 @@ jstring = A.word8 DOUBLE_QUOTE *> jstring_
320319
jstring_ :: Parser Text
321320
{-# INLINE jstring_ #-}
322321
jstring_ = do
323-
s <- A.takeWhile (\w -> w /= DOUBLE_QUOTE && w /= BACKSLASH && not (testBit w 7))
322+
-- not sure whether >= or bit hackery is faster
323+
-- perfectly, we shouldn't care, it's compiler job.
324+
s <- A.takeWhile (\w -> w /= DOUBLE_QUOTE && w /= BACKSLASH && w >= 0x20 && w < 0x80)
324325
let txt = TE.decodeUtf8 s
325-
w <- A.peekWord8
326-
case w of
327-
Nothing -> fail "string without end"
326+
mw <- A.peekWord8
327+
case mw of
328+
Nothing -> fail "string without end"
328329
Just DOUBLE_QUOTE -> A.anyWord8 $> txt
329-
_ -> jstringSlow s
330+
Just w | w < 0x20 -> fail "unescaped control character"
331+
_ -> jstringSlow s
330332

331333
jstringSlow :: B.ByteString -> Parser Text
332334
{-# INLINE jstringSlow #-}

aeson.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ library
175175
hs-source-dirs: ffi
176176
other-modules: Data.Aeson.Parser.UnescapeFFI
177177

178-
test-suite tests
178+
test-suite aeson-tests
179179
default-language: Haskell2010
180180
type: exitcode-stdio-1.0
181181
hs-source-dirs: tests ffi pure

tests/UnitTests.hs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,9 +505,6 @@ _blacklist = HashSet.fromList [
505505
, "i_string_not_in_unicode_range.json"
506506
, "i_string_truncated-utf-8.json"
507507
, "i_structure_UTF-8_BOM_empty_object.json"
508-
, "n_string_unescaped_crtl_char.json"
509-
, "n_string_unescaped_newline.json"
510-
, "n_string_unescaped_tab.json"
511508
, "string_1_escaped_invalid_codepoint.json"
512509
, "string_1_invalid_codepoint.json"
513510
, "string_1_invalid_codepoints.json"

0 commit comments

Comments
 (0)