From b1007dff664194ca0e800bd158e94456c5ab202a Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Wed, 1 Dec 2021 09:13:13 -0600 Subject: [PATCH 1/7] Remove unknown keyword arg from DateTime.parse This snuck in while addding tests for the `create_additions` feature. Caught by JRuby when we added the `limit` option to the Date/DateTime parsing methods, which causes this to be rejected as an unknown keyword. --- tests/json_addition_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/json_addition_test.rb b/tests/json_addition_test.rb index e95ace837..614c73556 100644 --- a/tests/json_addition_test.rb +++ b/tests/json_addition_test.rb @@ -165,7 +165,7 @@ def test_core def test_utc_datetime now = Time.now - d = DateTime.parse(now.to_s, :create_additions => true) # usual case + d = DateTime.parse(now.to_s) # usual case assert_equal d, parse(d.to_json, :create_additions => true) d = DateTime.parse(now.utc.to_s) # of = 0 assert_equal d, parse(d.to_json, :create_additions => true) From e816481e060a00394c5bd2e480cb35c87b1648e8 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Thu, 2 Dec 2021 15:55:01 +0900 Subject: [PATCH 2/7] Ignore java artifacts --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index e8b1a5226..274cae363 100644 --- a/.gitignore +++ b/.gitignore @@ -14,5 +14,7 @@ Gemfile.lock .DS_Store */**/Makefile */**/*.o +*/**/*.class +*/**/*.jar .byebug_history *.log From 75ada77b9664c1d1f0ae6e210f8db4919849561e Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Thu, 2 Dec 2021 16:42:41 +0900 Subject: [PATCH 3/7] Doc: Improve documentation on JSON#parse and JSON#parse! Co-authored-by: Bruno Gomes da Silva --- ext/json/ext/parser/parser.c | 1 + ext/json/ext/parser/parser.rl | 1 + 2 files changed, 2 insertions(+) diff --git a/ext/json/ext/parser/parser.c b/ext/json/ext/parser/parser.c index b1dc8810c..b7de60ddf 100644 --- a/ext/json/ext/parser/parser.c +++ b/ext/json/ext/parser/parser.c @@ -2950,6 +2950,7 @@ static const char MAYBE_UNUSED(_JSON_nfa_pop_trans)[] = { * * Parses the current JSON text _source_ and returns the complete data * structure as a result. +* It raises JSON::ParseError if fail to parse. */ static VALUE cParser_parse(VALUE self) { diff --git a/ext/json/ext/parser/parser.rl b/ext/json/ext/parser/parser.rl index f7be1a5ac..15e6b929f 100644 --- a/ext/json/ext/parser/parser.rl +++ b/ext/json/ext/parser/parser.rl @@ -839,6 +839,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) * * Parses the current JSON text _source_ and returns the complete data * structure as a result. + * It raises JSON::ParseError if fail to parse. */ static VALUE cParser_parse(VALUE self) { From b59368a8c23976d9e44adc8f8c284fdd954a0d33 Mon Sep 17 00:00:00 2001 From: Andrew Bromwich Date: Wed, 20 Apr 2022 22:30:35 +1000 Subject: [PATCH 4/7] Fix parser bug for empty string allocation When `HAVE_RB_ENC_INTERNED_STR` is enabled it is possible to pass through a null pointer to `rb_enc_interned_str` resulting in a segfault Fixes #495 --- ext/json/ext/parser/parser.c | 8 ++++++++ ext/json/ext/parser/parser.rl | 8 ++++++++ tests/json_parser_test.rb | 1 + 3 files changed, 17 insertions(+) diff --git a/ext/json/ext/parser/parser.c b/ext/json/ext/parser/parser.c index b7de60ddf..8b860c410 100644 --- a/ext/json/ext/parser/parser.c +++ b/ext/json/ext/parser/parser.c @@ -2363,9 +2363,17 @@ static VALUE json_string_unescape(char *string, char *stringEnd, int intern, int char buf[4]; if (bufferSize > MAX_STACK_BUFFER_SIZE) { +# ifdef HAVE_RB_ENC_INTERNED_STR + bufferStart = buffer = ALLOC_N(char, bufferSize ? bufferSize : 1); +# else bufferStart = buffer = ALLOC_N(char, bufferSize); +# endif } else { +# ifdef HAVE_RB_ENC_INTERNED_STR + bufferStart = buffer = ALLOCA_N(char, bufferSize ? bufferSize : 1); +# else bufferStart = buffer = ALLOCA_N(char, bufferSize); +# endif } while (pe < stringEnd) { diff --git a/ext/json/ext/parser/parser.rl b/ext/json/ext/parser/parser.rl index 15e6b929f..2dee80ee3 100644 --- a/ext/json/ext/parser/parser.rl +++ b/ext/json/ext/parser/parser.rl @@ -462,9 +462,17 @@ static VALUE json_string_unescape(char *string, char *stringEnd, int intern, int char buf[4]; if (bufferSize > MAX_STACK_BUFFER_SIZE) { +# ifdef HAVE_RB_ENC_INTERNED_STR + bufferStart = buffer = ALLOC_N(char, bufferSize ? bufferSize : 1); +# else bufferStart = buffer = ALLOC_N(char, bufferSize); +# endif } else { +# ifdef HAVE_RB_ENC_INTERNED_STR + bufferStart = buffer = ALLOCA_N(char, bufferSize ? bufferSize : 1); +# else bufferStart = buffer = ALLOCA_N(char, bufferSize); +# endif } while (pe < stringEnd) { diff --git a/tests/json_parser_test.rb b/tests/json_parser_test.rb index dce693e54..00b254fc6 100644 --- a/tests/json_parser_test.rb +++ b/tests/json_parser_test.rb @@ -84,6 +84,7 @@ def test_parse_simple_objects assert_equal({ "a" => 23 }, parse(' { "a" : 23 } ')) assert_equal({ "a" => 0.23 }, parse(' { "a" : 0.23 } ')) assert_equal({ "a" => 0.23 }, parse(' { "a" : 0.23 } ')) + assert_equal({ "" => 123 }, parse('{"":123}')) end def test_parse_numbers From 7555edaaedd6d3947ca2655cd8c01e11f41433c4 Mon Sep 17 00:00:00 2001 From: Florian Frank Date: Mon, 16 May 2022 14:16:48 +0200 Subject: [PATCH 5/7] Add all_images gem for local testing --- .all_images.yml | 17 +++++++++++++++++ Gemfile | 1 + 2 files changed, 18 insertions(+) create mode 100644 .all_images.yml diff --git a/.all_images.yml b/.all_images.yml new file mode 100644 index 000000000..9178beb50 --- /dev/null +++ b/.all_images.yml @@ -0,0 +1,17 @@ +dockerfile: |- + RUN apk add --no-cache build-base git ragel + RUN gem update --system + RUN gem install gem_hadar bundler +script: &script |- + echo -e "\e[1m" + ruby -v + echo -e "\e[0m" + bundle + rake clean test + +images: + ruby:3.1-alpine: *script + ruby:3.0-alpine: *script + ruby:2.7-alpine: *script + ruby:2.6-alpine: *script + ruby:2.5-alpine: *script diff --git a/Gemfile b/Gemfile index 721964460..dedab3ca7 100644 --- a/Gemfile +++ b/Gemfile @@ -15,3 +15,4 @@ end gem "rake" gem "test-unit" +gem "all_images" From 5de358f655ea7bc17b56a9e0c1191b93ac254d85 Mon Sep 17 00:00:00 2001 From: Florian Frank Date: Mon, 16 May 2022 14:20:48 +0200 Subject: [PATCH 6/7] Bump version to 2.6.2 --- VERSION | 2 +- lib/json/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 6a6a3d8e3..097a15a2a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.6.1 +2.6.2 diff --git a/lib/json/version.rb b/lib/json/version.rb index 35e8dd325..9bedb65fa 100644 --- a/lib/json/version.rb +++ b/lib/json/version.rb @@ -1,7 +1,7 @@ # frozen_string_literal: false module JSON # JSON version - VERSION = '2.6.1' + VERSION = '2.6.2' VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc: VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc: VERSION_MINOR = VERSION_ARRAY[1] # :nodoc: From 5d9d8f3799f2f65ebaa7b485fd6078ce5c79818c Mon Sep 17 00:00:00 2001 From: Florian Frank Date: Mon, 16 May 2022 14:33:21 +0200 Subject: [PATCH 7/7] Upgrade to newest release w/out required_ruby_version --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index dedab3ca7..a90dd9d27 100644 --- a/Gemfile +++ b/Gemfile @@ -15,4 +15,4 @@ end gem "rake" gem "test-unit" -gem "all_images" +gem "all_images", "~> 0"