From 331e9b3f1248f868f86ed04866ea403248e3fb99 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Wed, 26 Feb 2025 12:17:45 -0500 Subject: [PATCH 1/2] avoid nothing in `parse_jsconstant ` return union --- src/Parser.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Parser.jl b/src/Parser.jl index 6bc5df2..b8254c1 100644 --- a/src/Parser.jl +++ b/src/Parser.jl @@ -174,7 +174,7 @@ end function parse_jsconstant(::ParserContext{<:Any,<:Any,AllowNanInf,NullValue}, ps::ParserState) where {AllowNanInf,NullValue} c = advance!(ps) - if c == LATIN_T # true + ret = if c == LATIN_T # true skip!(ps, LATIN_R, LATIN_U, LATIN_E) true elseif c == LATIN_F # false @@ -192,6 +192,7 @@ function parse_jsconstant(::ParserContext{<:Any,<:Any,AllowNanInf,NullValue}, else _error(E_UNEXPECTED_CHAR, ps) end + return ret::Union{Bool, Float64} end function parse_array(pc::ParserContext, ps::ParserState) From 67818c69ec0cb7a4c9994e19175b9005f0d591f8 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Wed, 26 Feb 2025 12:25:08 -0500 Subject: [PATCH 2/2] try another way --- src/Parser.jl | 4 ++-- src/specialized.jl | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Parser.jl b/src/Parser.jl index b8254c1..1cd78c1 100644 --- a/src/Parser.jl +++ b/src/Parser.jl @@ -174,7 +174,7 @@ end function parse_jsconstant(::ParserContext{<:Any,<:Any,AllowNanInf,NullValue}, ps::ParserState) where {AllowNanInf,NullValue} c = advance!(ps) - ret = if c == LATIN_T # true + if c == LATIN_T # true skip!(ps, LATIN_R, LATIN_U, LATIN_E) true elseif c == LATIN_F # false @@ -192,7 +192,6 @@ function parse_jsconstant(::ParserContext{<:Any,<:Any,AllowNanInf,NullValue}, else _error(E_UNEXPECTED_CHAR, ps) end - return ret::Union{Bool, Float64} end function parse_array(pc::ParserContext, ps::ParserState) @@ -394,6 +393,7 @@ function parse_number(pc::ParserContext{<:Any,<:Any,AllowNanInf}, ps::ParserStat isint = false elseif AllowNanInf && c == LATIN_UPPER_I infinity = parse_jsconstant(pc, ps) + infinity === nothing && _error("Invalid infinity value", ps) resize!(number, 0) return (negative ? -infinity : infinity) else diff --git a/src/specialized.jl b/src/specialized.jl index e0f0e3b..b721994 100644 --- a/src/specialized.jl +++ b/src/specialized.jl @@ -145,6 +145,7 @@ function parse_number(pc::ParserContext{<:Any,<:Any,AllowNanInf}, ps::MemoryPars elseif AllowNanInf && LATIN_UPPER_I == c ps.s = p infinity = parse_jsconstant(pc, ps) + infinity === nothing && _error("Invalid infinity value", ps) return (negative ? -infinity : infinity) else break