summary refs log tree commit
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2011-07-08 06:46:06 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2011-07-08 06:59:35 +0900
commit1b19c43a4f459988474f86ccbbfc92a420af58e8 (patch)
tree16efe5f1ffd17c3b93466a229085d00e6680f5b0
parent08793aa47dfca15f678842fd5cd583fe2fb67136 (diff)
downloadruby-json-1b19c43a4f459988474f86ccbbfc92a420af58e8.tar.gz
should not modify argument
 * ext/json/ext/parser/parser.h (FORCE_UTF8): should not modify
   encoding of the argument.
-rw-r--r--ext/json/ext/parser/parser.h2
-rwxr-xr-xtests/test_json.rb6
2 files changed, 7 insertions, 1 deletions
diff --git a/ext/json/ext/parser/parser.h b/ext/json/ext/parser/parser.h
index 2be640e..f2ce5a4 100644
--- a/ext/json/ext/parser/parser.h
+++ b/ext/json/ext/parser/parser.h
@@ -9,7 +9,7 @@
 
 #ifdef HAVE_RUBY_ENCODING_H
 #include "ruby/encoding.h"
-#define FORCE_UTF8(obj) rb_enc_associate((obj), rb_utf8_encoding())
+#define FORCE_UTF8(obj) ((obj) = rb_enc_associate(rb_str_dup(obj), rb_utf8_encoding()))
 #else
 #define FORCE_UTF8(obj)
 #endif
diff --git a/tests/test_json.rb b/tests/test_json.rb
index 5b43ec9..825a507 100755
--- a/tests/test_json.rb
+++ b/tests/test_json.rb
@@ -415,4 +415,10 @@ EOT
       assert_raise(TypeError, '[ruby-core:35079]') {parser.source}
     end
   end
+
+  def test_argument_encoding
+    source = "{}".force_encoding("ascii-8bit")
+    JSON::Parser.new(source)
+    assert_equal Encoding::ASCII_8BIT, source.encoding
+  end if defined?(Encoding::ASCII_8BIT)
 end