From 5924c9ef4a50b4632ba28e112b4d7bd472332760 Mon Sep 17 00:00:00 2001 From: Jason Penny Date: Tue, 29 Aug 2023 17:14:43 -0400 Subject: [PATCH 1/3] Add test that passes with v3.14.2 and fails from v3.15+ --- test/test_strict.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/test_strict.rb b/test/test_strict.rb index 662622d7..54502c56 100755 --- a/test/test_strict.rb +++ b/test/test_strict.rb @@ -69,6 +69,16 @@ def test_float dump_and_load(-2.48e100 * 1.0e10, false) end + def test_invalid_float + begin + Oj.load("64ecb72d29191067f91ff95b") + rescue Oj::ParseError => e + assert(e.message == "Invalid float") + return + end + assert(false, "*** expected an exception") + end + def test_nan_dump assert_equal('null', Oj.dump(0/0.0, :nan => :null)) assert_equal('3.3e14159265358979323846', Oj.dump(0/0.0, :nan => :huge)) From a5961109cefa5b944c33b84f55bfa006e202f075 Mon Sep 17 00:00:00 2001 From: Jason Penny Date: Tue, 29 Aug 2023 17:18:44 -0400 Subject: [PATCH 2/3] Fix 'Invalid float' error --- ext/oj/parse.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ext/oj/parse.c b/ext/oj/parse.c index caeab6dd..342bfece 100644 --- a/ext/oj/parse.c +++ b/ext/oj/parse.c @@ -875,7 +875,11 @@ oj_num_as_value(NumInfo ni) { double d = strtod(ni->str, &end); if ((long)ni->len != (long)(end - ni->str)) { + if (Qnil == ni->pi->err_class) { + rb_raise(oj_parse_error_class, "Invalid float"); + } else { rb_raise(ni->pi->err_class, "Invalid float"); + } } rnum = rb_float_new(d); } From 73ed6ba42a394364c0a9953b92f34e2109be796f Mon Sep 17 00:00:00 2001 From: Jason Penny Date: Wed, 30 Aug 2023 09:16:10 -0400 Subject: [PATCH 3/3] clang-format -i ext/oj/parse.c --- ext/oj/parse.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ext/oj/parse.c b/ext/oj/parse.c index 342bfece..650e7006 100644 --- a/ext/oj/parse.c +++ b/ext/oj/parse.c @@ -875,11 +875,11 @@ oj_num_as_value(NumInfo ni) { double d = strtod(ni->str, &end); if ((long)ni->len != (long)(end - ni->str)) { - if (Qnil == ni->pi->err_class) { - rb_raise(oj_parse_error_class, "Invalid float"); - } else { - rb_raise(ni->pi->err_class, "Invalid float"); - } + if (Qnil == ni->pi->err_class) { + rb_raise(oj_parse_error_class, "Invalid float"); + } else { + rb_raise(ni->pi->err_class, "Invalid float"); + } } rnum = rb_float_new(d); }