[前][次][番号順一覧][スレッド一覧]

ruby-changes:46209

From: hsbt <ko1@a...>
Date: Wed, 12 Apr 2017 09:21:24 +0900 (JST)
Subject: [ruby-changes:46209] hsbt:r58323 (trunk): Merge json-2.0.4.

hsbt	2017-04-12 09:21:18 +0900 (Wed, 12 Apr 2017)

  New Revision: 58323

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58323

  Log:
    Merge json-2.0.4.
    
      * https://github.com/flori/json/releases/tag/v2.0.4
      * https://github.com/flori/json/blob/09fabeb03e73ed88dc8ce8f19d76ac59e51dae20/CHANGES.md#2017-03-23-204

  Modified files:
    trunk/ext/json/fbuffer/fbuffer.h
    trunk/ext/json/generator/generator.c
    trunk/ext/json/generator/generator.h
    trunk/ext/json/json.gemspec
    trunk/ext/json/lib/json/version.rb
    trunk/ext/json/parser/parser.c
    trunk/ext/json/parser/parser.rl
    trunk/test/json/json_encoding_test.rb
    trunk/test/json/json_generator_test.rb
Index: test/json/json_generator_test.rb
===================================================================
--- test/json/json_generator_test.rb	(revision 58322)
+++ test/json/json_generator_test.rb	(revision 58323)

Property changes on: test/json/json_generator_test.rb
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: ext/json/json.gemspec
===================================================================
Binary files ext/json/json.gemspec	(revision 58322) and ext/json/json.gemspec	(revision 58323) differ
Index: ext/json/parser/parser.rl
===================================================================
--- ext/json/parser/parser.rl	(revision 58322)
+++ ext/json/parser/parser.rl	(revision 58323)
@@ -446,13 +446,21 @@ static VALUE json_string_unescape(VALUE https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.rl#L446
                     break;
                 case 'u':
                     if (pe > stringEnd - 4) {
-                        return Qnil;
+                      rb_enc_raise(
+                        EXC_ENCODING eParserError,
+                        "%u: incomplete unicode character escape sequence at '%s'", __LINE__, p
+                      );
                     } else {
                         UTF32 ch = unescape_unicode((unsigned char *) ++pe);
                         pe += 3;
                         if (UNI_SUR_HIGH_START == (ch & 0xFC00)) {
                             pe++;
-                            if (pe > stringEnd - 6) return Qnil;
+                            if (pe > stringEnd - 6) {
+                              rb_enc_raise(
+                                EXC_ENCODING eParserError,
+                                "%u: incomplete surrogate pair at '%s'", __LINE__, p
+                                );
+                            }
                             if (pe[0] == '\\' && pe[1] == 'u') {
                                 UTF32 sur = unescape_unicode((unsigned char *) pe + 2);
                                 ch = (((ch & 0x3F) << 10) | ((((ch >> 6) & 0xF) + 1) << 16)
@@ -570,7 +578,7 @@ static VALUE convert_encoding(VALUE sour https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.rl#L578
     }
     FORCE_UTF8(source);
   } else {
-    source = rb_str_conv_enc(source, NULL, rb_utf8_encoding());
+    source = rb_str_conv_enc(source, rb_enc_get(source), rb_utf8_encoding());
   }
 #endif
     return source;
Index: ext/json/parser/parser.c
===================================================================
--- ext/json/parser/parser.c	(revision 58322)
+++ ext/json/parser/parser.c	(revision 58323)
@@ -1435,13 +1435,21 @@ static VALUE json_string_unescape(VALUE https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1435
                     break;
                 case 'u':
                     if (pe > stringEnd - 4) {
-                        return Qnil;
+                      rb_enc_raise(
+                        EXC_ENCODING eParserError,
+                        "%u: incomplete unicode character escape sequence at '%s'", __LINE__, p
+                      );
                     } else {
                         UTF32 ch = unescape_unicode((unsigned char *) ++pe);
                         pe += 3;
                         if (UNI_SUR_HIGH_START == (ch & 0xFC00)) {
                             pe++;
-                            if (pe > stringEnd - 6) return Qnil;
+                            if (pe > stringEnd - 6) {
+                              rb_enc_raise(
+                                EXC_ENCODING eParserError,
+                                "%u: incomplete surrogate pair at '%s'", __LINE__, p
+                                );
+                            }
                             if (pe[0] == '\\' && pe[1] == 'u') {
                                 UTF32 sur = unescape_unicode((unsigned char *) pe + 2);
                                 ch = (((ch & 0x3F) << 10) | ((((ch >> 6) & 0xF) + 1) << 16)
@@ -1471,7 +1479,7 @@ static VALUE json_string_unescape(VALUE https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1479
 }
 
 
-#line 1475 "parser.c"
+#line 1483 "parser.c"
 enum {JSON_string_start = 1};
 enum {JSON_string_first_final = 8};
 enum {JSON_string_error = 0};
@@ -1479,7 +1487,7 @@ enum {JSON_string_error = 0}; https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1487
 enum {JSON_string_en_main = 1};
 
 
-#line 504 "parser.rl"
+#line 512 "parser.rl"
 
 
 static int
@@ -1501,15 +1509,15 @@ static char *JSON_parse_string(JSON_Pars https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1509
 
     *result = rb_str_buf_new(0);
 
-#line 1505 "parser.c"
+#line 1513 "parser.c"
 	{
 	cs = JSON_string_start;
 	}
 
-#line 525 "parser.rl"
+#line 533 "parser.rl"
     json->memo = p;
 
-#line 1513 "parser.c"
+#line 1521 "parser.c"
 	{
 	if ( p == pe )
 		goto _test_eof;
@@ -1534,7 +1542,7 @@ case 2: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1542
 		goto st0;
 	goto st2;
 tr2:
-#line 490 "parser.rl"
+#line 498 "parser.rl"
 	{
         *result = json_string_unescape(*result, json->memo + 1, p);
         if (NIL_P(*result)) {
@@ -1545,14 +1553,14 @@ tr2: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1553
             {p = (( p + 1))-1;}
         }
     }
-#line 501 "parser.rl"
+#line 509 "parser.rl"
 	{ p--; {p++; cs = 8; goto _out;} }
 	goto st8;
 st8:
 	if ( ++p == pe )
 		goto _test_eof8;
 case 8:
-#line 1556 "parser.c"
+#line 1564 "parser.c"
 	goto st0;
 st3:
 	if ( ++p == pe )
@@ -1628,7 +1636,7 @@ case 7: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1636
 	_out: {}
 	}
 
-#line 527 "parser.rl"
+#line 535 "parser.rl"
 
     if (json->create_additions && RTEST(match_string = json->match_string)) {
           VALUE klass;
@@ -1675,7 +1683,7 @@ static VALUE convert_encoding(VALUE sour https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1683
     }
     FORCE_UTF8(source);
   } else {
-    source = rb_str_conv_enc(source, NULL, rb_utf8_encoding());
+    source = rb_str_conv_enc(source, rb_enc_get(source), rb_utf8_encoding());
   }
 #endif
     return source;
@@ -1808,7 +1816,7 @@ static VALUE cParser_initialize(int argc https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1816
 }
 
 
-#line 1812 "parser.c"
+#line 1820 "parser.c"
 enum {JSON_start = 1};
 enum {JSON_first_final = 10};
 enum {JSON_error = 0};
@@ -1816,7 +1824,7 @@ enum {JSON_error = 0}; https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1824
 enum {JSON_en_main = 1};
 
 
-#line 720 "parser.rl"
+#line 728 "parser.rl"
 
 
 /*
@@ -1833,16 +1841,16 @@ static VALUE cParser_parse(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1841
   GET_PARSER;
 
 
-#line 1837 "parser.c"
+#line 1845 "parser.c"
 	{
 	cs = JSON_start;
 	}
 
-#line 736 "parser.rl"
+#line 744 "parser.rl"
   p = json->source;
   pe = p + json->len;
 
-#line 1846 "parser.c"
+#line 1854 "parser.c"
 	{
 	if ( p == pe )
 		goto _test_eof;
@@ -1876,7 +1884,7 @@ st0: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1884
 cs = 0;
 	goto _out;
 tr2:
-#line 712 "parser.rl"
+#line 720 "parser.rl"
 	{
         char *np = JSON_parse_value(json, p, pe, &result, 0);
         if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
@@ -1886,7 +1894,7 @@ st10: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1894
 	if ( ++p == pe )
 		goto _test_eof10;
 case 10:
-#line 1890 "parser.c"
+#line 1898 "parser.c"
 	switch( (*p) ) {
 		case 13: goto st10;
 		case 32: goto st10;
@@ -1975,7 +1983,7 @@ case 9: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1983
 	_out: {}
 	}
 
-#line 739 "parser.rl"
+#line 747 "parser.rl"
 
   if (cs >= JSON_first_final && p == pe) {
     return result;
Index: ext/json/fbuffer/fbuffer.h
===================================================================
--- ext/json/fbuffer/fbuffer.h	(revision 58322)
+++ ext/json/fbuffer/fbuffer.h	(revision 58323)
@@ -12,9 +12,6 @@ https://github.com/ruby/ruby/blob/trunk/ext/json/fbuffer/fbuffer.h#L12
 #define RFLOAT_VALUE(val) (RFLOAT(val)->value)
 #endif
 
-#ifndef RARRAY_PTR
-#define RARRAY_PTR(ARRAY) RARRAY(ARRAY)->ptr
-#endif
 #ifndef RARRAY_LEN
 #define RARRAY_LEN(ARRAY) RARRAY(ARRAY)->len
 #endif
Index: ext/json/generator/generator.h
===================================================================
--- ext/json/generator/generator.h	(revision 58322)
+++ ext/json/generator/generator.h	(revision 58323)
@@ -1,7 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ext/json/generator/generator.h#L1
 #ifndef _GENERATOR_H_
 #define _GENERATOR_H_
 
-#include <string.h>
 #include <math.h>
 #include <ctype.h>
 
Index: ext/json/generator/generator.c
===================================================================
--- ext/json/generator/generator.c	(revision 58322)
+++ ext/json/generator/generator.c	(revision 58323)
@@ -308,7 +308,7 @@ static char *fstrndup(const char *ptr, u https://github.com/ruby/ruby/blob/trunk/ext/json/generator/generator.c#L308
   char *result;
   if (len <= 0) return NULL;
   result = ALLOC_N(char, len);
-  memccpy(result, ptr, 0, len);
+  memcpy(result, ptr, len);
   return result;
 }
 
@@ -1062,7 +1062,7 @@ static VALUE cState_indent_set(VALUE sel https://github.com/ruby/ruby/blob/trunk/ext/json/generator/generator.c#L1062
         }
     } else {
         if (state->indent) ruby_xfree(state->indent);
-        state->indent = strdup(RSTRING_PTR(indent));
+        state->indent = fstrndup(RSTRING_PTR(indent), len);
         state->indent_len = len;
     }
     return Qnil;
@@ -1100,7 +1100,7 @@ static VALUE cState_space_set(VALUE self https://github.com/ruby/ruby/blob/trunk/ext/json/generator/generator.c#L1100
         }
     } else {
         if (state->space) ruby_xfree(state->space);
-        state->space = strdup(RSTRING_PTR(space));
+        state->space = fstrndup(RSTRING_PTR(space), len);
         state->space_len = len;
     }
     return Qnil;
@@ -1136,7 +1136,7 @@ static VALUE cState_space_before_set(VAL https://github.com/ruby/ruby/blob/trunk/ext/json/generator/generator.c#L1136
         }
     } else {
         if (state->space_before) ruby_xfree(state->space_before);
-        state->space_before = strdup(RSTRING_PTR(space_before));
+        state->space_before = fstrndup(RSTRING_PTR(space_before), len);
         state->space_before_len = len;
     }
     return Qnil;
@@ -1173,7 +1173,7 @@ static VALUE cState_object_nl_set(VALUE https://github.com/ruby/ruby/blob/trunk/ext/json/generator/generator.c#L1173
         }
     } else {
         if (state->object_nl) ruby_xfree(state->object_nl);
-        state->object_nl = strdup(RSTRING_PTR(object_nl));
+        state->object_nl = fstrndup(RSTRING_PTR(object_nl), len);
         state->object_nl_len = len;
     }
     return Qnil;
@@ -1208,7 +1208,7 @@ static VALUE cState_array_nl_set(VALUE s https://github.com/ruby/ruby/blob/trunk/ext/json/generator/generator.c#L1208
         }
     } else {
         if (state->array_nl) ruby_xfree(state->array_nl);
-        state->array_nl = strdup(RSTRING_PTR(array_nl));
+        state->array_nl = fstrndup(RSTRING_PTR(array_nl), len);
         state->array_nl_len = len;
     }
     return Qnil;
Index: ext/json/lib/json/version.rb
===================================================================
--- ext/json/lib/json/version.rb	(revision 58322)
+++ ext/json/lib/json/version.rb	(revision 58323)
@@ -1,7 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ext/json/lib/json/version.rb#L1
 # frozen_string_literal: false
 module JSON
   # JSON version
-  VERSION         = '2.0.2'
+  VERSION         = '2.0.4'
   VERSION_ARRAY   = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
   VERSION_MAJOR   = VERSION_ARRAY[0] # :nodoc:
   VERSION_MINOR   = VERSION_ARRAY[1] # :nodoc:
Index: test/json/json_encoding_test.rb
===================================================================
--- test/json/json_encoding_test.rb	(revision 58322)
+++ test/json/json_encoding_test.rb	(revision 58323)
@@ -79,6 +79,8 @@ class JSONEncodingTest < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/json/json_encoding_test.rb#L79
     json = '["\ud840\udc01"]'
     assert_equal json, generate(utf8, :ascii_only => true)
     assert_equal utf8, parse(json)
+    assert_raises(JSON::ParserError) { parse('"\u"') }
+    assert_raises(JSON::ParserError) { parse('"\ud800"') }
   end
 
   def test_chars

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]