diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2011-07-08 06:46:06 +0900 |
---|---|---|
committer | Florian Frank <flori@ping.de> | 2011-07-08 01:24:58 +0200 |
commit | 5e4b83035f452c0b1c62833340fcaea63e4f21ab (patch) | |
tree | 16efe5f1ffd17c3b93466a229085d00e6680f5b0 | |
parent | 72b05a2bc42bc80c9f1b55948110a9a050c18ba8 (diff) | |
download | json-5e4b83035f452c0b1c62833340fcaea63e4f21ab.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.h | 2 | ||||
-rwxr-xr-x | tests/test_json.rb | 6 |
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 |