diff --git a/spec/std/json/lexer_spec.cr b/spec/std/json/lexer_spec.cr index 4136fbe22d4c..fa9bfd78dbfd 100644 --- a/spec/std/json/lexer_spec.cr +++ b/spec/std/json/lexer_spec.cr @@ -92,10 +92,12 @@ describe "Json::Lexer" do it_lexes_json_float "0.123", 0.123 it_lexes_json_float "1234.567", 1234.567 it_lexes_json_float "0e1", 0 + it_lexes_json_float "0E1", 0 it_lexes_json_float "0.1e1", 0.1e1 it_lexes_json_float "0e+12", 0 it_lexes_json_float "0e-12", 0 it_lexes_json_float "1e2", 1e2 + it_lexes_json_float "1E2", 1e2 it_lexes_json_float "1e+12", 1e12 it_lexes_json_float "1.2e-3", 1.2e-3 it_lexes_json_float "9.91343313498688", 9.91343313498688 diff --git a/src/json/lexer.cr b/src/json/lexer.cr index da10177ae3d6..c468aab48554 100644 --- a/src/json/lexer.cr +++ b/src/json/lexer.cr @@ -200,19 +200,21 @@ abstract class Json::Lexer next_char end - if current_char == '0' + case current_char + when '0' next_char - if current_char == '.' + case current_char + when '.' consume_float(negative, integer) - elsif current_char == 'e' + when 'e', 'E' consume_exponent(negative, integer.to_f64) - elsif '0' <= current_char <= '9' || current_char == 'e' || current_char == 'E' + when '0' .. '9' unexpected_char else @token.type = :INT @token.int_value = 0_i64 end - elsif '1' <= current_char <= '9' + when '1' .. '9' integer = (current_char.ord - '0'.ord).to_i64 char = next_char while '0' <= char <= '9' @@ -224,7 +226,7 @@ abstract class Json::Lexer case char when '.' consume_float(negative, integer) - when 'e' + when 'e', 'E' consume_exponent(negative, integer.to_f64) else @token.type = :INT