After call Oj.mimic_JSON or Oj::Rails.mimic_JSON JSON.parseto raises Oj::ParseError (instead of JSON::ParserError) when json string contains token started with 1+ digits and "e" letter but is not a valid float (for ex. 84e crash, but 84e-1 is not)
If I comment out Oj.mimic_JSON and Oj::Rails.mimic_JSON than below tests pass.
reproduce
# frozen_string_literal: true
begin
require 'bundler/inline'
rescue LoadError => e
warn 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
puts "Ruby #{RUBY_VERSION}"
gemfile(true) do
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem 'activesupport'
gem 'oj', '3.15.0'
end
require 'active_support'
require 'json'
require 'oj'
Oj.mimic_JSON()
# Oj::Rails.mimic_JSON()
require 'minitest/autorun'
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
class BugTest < Minitest::Test
def test_invalid_float_short
error = assert_raises(::JSON::ParserError) do
::JSON.parse('{ "foo": 84e }')
end
assert_equal "unexpected token at '{ \"foo\": 84e }'", error.message
end
def test_invalid_float_long
error = assert_raises(::JSON::ParserError) do
::JSON.parse('{ "foo": 84eb234 }')
end
assert_equal "unexpected token at '{ \"foo\": 84eb234 }'", error.message
end
end
log
Ruby 3.2.2
Fetching gem metadata from https://rubygems.org/........
Resolving dependencies...
Using concurrent-ruby 1.2.2
Using minitest 5.18.1
Using oj 3.15.0
Using bundler 2.4.12
Using tzinfo 2.0.6
Using i18n 1.14.1
Using activesupport 7.0.6
Minitest::Assertion: [JSON::ParserError] exception expected, not
Class: <Oj::ParseError>
Message: <"Invalid float">
---Backtrace---
/home/senid/projects/bug_reports/oj/test_oj_parse_error_expose_bug.rb:42:in `parse'
/home/senid/projects/bug_reports/oj/test_oj_parse_error_expose_bug.rb:42:in `block in test_invalid_float_long'
---------------
/home/senid/projects/bug_reports/oj/test_oj_parse_error_expose_bug.rb:41:in `test_invalid_float_long'
Minitest::Assertion: [JSON::ParserError] exception expected, not
Class: <Oj::ParseError>
Message: <"Invalid float">
---Backtrace---
/home/senid/projects/bug_reports/oj/test_oj_parse_error_expose_bug.rb:35:in `parse'
/home/senid/projects/bug_reports/oj/test_oj_parse_error_expose_bug.rb:35:in `block in test_invalid_float_short'
---------------
/home/senid/projects/bug_reports/oj/test_oj_parse_error_expose_bug.rb:34:in `test_invalid_float_short'
Process finished with exit code 1
After call
Oj.mimic_JSON
orOj::Rails.mimic_JSON
JSON.parse
to raisesOj::ParseError
(instead ofJSON::ParserError
) when json string contains token started with 1+ digits and "e" letter but is not a valid float (for ex. 84e crash, but 84e-1 is not)If I comment out
Oj.mimic_JSON
andOj::Rails.mimic_JSON
than below tests pass.reproduce
log