From 1b19c43a4f459988474f86ccbbfc92a420af58e8 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Fri, 8 Jul 2011 06:46:06 +0900 Subject: should not modify argument * ext/json/ext/parser/parser.h (FORCE_UTF8): should not modify encoding of the argument. --- ext/json/ext/parser/parser.h | 2 +- tests/test_json.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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 -- cgit v1.2.3-24-ge0c7