From 3abe1ffb27768d6eff8326c93071b29e91bbeba5 Mon Sep 17 00:00:00 2001 From: Jacob Quinn Date: Fri, 30 Jul 2021 00:29:54 -0600 Subject: [PATCH] Fix case when float parsing, we failed to check eof before peeking Discovered while porting JSON.jl to Parsers 2.0. Unfortunately, the byte peeking was under an `@inbounds`, so this usually wouldn't error unless julia was run with `--check-bounds=yes` (which is the default when running tests thankfully). Good candidate to backport for another 1.X release. --- src/floats.jl | 5 +++++ test/floats.jl | 3 +++ 2 files changed, 8 insertions(+) diff --git a/src/floats.jl b/src/floats.jl index d6ec4b5..b5ce7be 100644 --- a/src/floats.jl +++ b/src/floats.jl @@ -291,6 +291,11 @@ end if negexp || b == UInt8('+') pos += 1 incr!(source) + if eof(source, pos, len) + # it's an error to have a "dangling" '-' or '+', so input was something like "1.1e-" + code |= INVALID | EOF + @goto done + end end b = peekbyte(source, pos) - UInt8('0') if b > 0x09 diff --git a/test/floats.jl b/test/floats.jl index 820a35e..c2c7217 100644 --- a/test/floats.jl +++ b/test/floats.jl @@ -363,4 +363,7 @@ for _ = 1:1000 @test Base.parse(Float16, str) === Parsers.parse(Float16, str) end +# discovered from JSON tests +@test Parsers.tryparse(Float64, "0e+") === nothing + end # @testset