summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-07-08 07:40:41 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-07-08 07:40:41 +0000
commit4902ef7d591fb01f6c9f70ec194e147c47935541 (patch)
tree223abaa69bf0f3a4effee7e478b95c471e09ae68
parentb16fd08622a5b79259c7af22ef2ce8b06652d79e (diff)
* ext/json/parser/parser.rl (convert_encoding): should not modify
the argument. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32458 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--ext/json/parser/parser.c11
-rw-r--r--ext/json/parser/parser.rl1
-rwxr-xr-xtest/json/test_json.rb13
4 files changed, 24 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 81b3548b73..49844d4d3f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,7 @@
-Fri Jul 8 16:39:03 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Fri Jul 8 16:40:38 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * ext/json/parser/parser.rl (convert_encoding): should not modify
+ the argument.
* ext/json/parser/parser.rl (convert_encoding): no needs to use
force_encoding.
diff --git a/ext/json/parser/parser.c b/ext/json/parser/parser.c
index 817597ede4..04bedf33a7 100644
--- a/ext/json/parser/parser.c
+++ b/ext/json/parser/parser.c
@@ -1551,6 +1551,7 @@ static VALUE convert_encoding(VALUE source)
} else if (len >= 4 && ptr[1] == 0 && ptr[3] == 0) {
source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_16LE);
} else {
+ source = rb_str_dup(source);
FORCE_UTF8(source);
}
} else {
@@ -1694,16 +1695,16 @@ static VALUE cParser_parse(VALUE self)
GET_PARSER;
-#line 1698 "parser.c"
+#line 1699 "parser.c"
{
cs = JSON_start;
}
-#line 695 "parser.rl"
+#line 696 "parser.rl"
p = json->source;
pe = p + json->len;
-#line 1707 "parser.c"
+#line 1708 "parser.c"
{
if ( p == pe )
goto _test_eof;
@@ -1780,7 +1781,7 @@ st10:
if ( ++p == pe )
goto _test_eof10;
case 10:
-#line 1784 "parser.c"
+#line 1785 "parser.c"
switch( (*p) ) {
case 13: goto st10;
case 32: goto st10;
@@ -1837,7 +1838,7 @@ case 9:
_out: {}
}
-#line 698 "parser.rl"
+#line 699 "parser.rl"
if (cs >= JSON_first_final && p == pe) {
return result;
diff --git a/ext/json/parser/parser.rl b/ext/json/parser/parser.rl
index abd056f18c..07319a8fd7 100644
--- a/ext/json/parser/parser.rl
+++ b/ext/json/parser/parser.rl
@@ -549,6 +549,7 @@ static VALUE convert_encoding(VALUE source)
} else if (len >= 4 && ptr[1] == 0 && ptr[3] == 0) {
source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_16LE);
} else {
+ source = rb_str_dup(source);
FORCE_UTF8(source);
}
} else {
diff --git a/test/json/test_json.rb b/test/json/test_json.rb
index 4c724fd36e..5f186f0c08 100755
--- a/test/json/test_json.rb
+++ b/test/json/test_json.rb
@@ -398,4 +398,17 @@ EOT
json = JSON::Parser.allocate
assert_raises(TypeError, '[ruby-core:35079]') {json.source}
end
+
+ def test_argument_encoding
+ source = "{}".force_encoding("ascii-8bit")
+ JSON::Parser.new(source)
+ assert_equal Encoding::ASCII_8BIT, source.encoding
+ end
+
+ def test_frozen_argument
+ source = "{}".force_encoding("ascii-8bit")
+ source.freeze
+ parser = nil
+ assert_nothing_raised {parser = JSON::Parser.new(source)}
+ end
end