зеркало из https://github.com/github/ruby.git
string.c: respect BOM
* string.c (get_encoding): respect BOM on pseudo encodings. [ruby-dev:47895] [Bug #9415] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44606 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
77ae7b2e83
Коммит
6951fbca43
|
@ -1,3 +1,8 @@
|
||||||
|
Wed Jan 15 14:04:33 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* string.c (get_encoding): respect BOM on pseudo encodings.
|
||||||
|
[ruby-dev:47895] [Bug #9415]
|
||||||
|
|
||||||
Wed Jan 15 14:03:47 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Wed Jan 15 14:03:47 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* string.c (get_actual_encoding): get actual encoding according to
|
* string.c (get_actual_encoding): get actual encoding according to
|
||||||
|
|
8
string.c
8
string.c
|
@ -121,7 +121,7 @@ VALUE rb_cSymbol;
|
||||||
#define STR_HEAP_PTR(str) (RSTRING(str)->as.heap.ptr)
|
#define STR_HEAP_PTR(str) (RSTRING(str)->as.heap.ptr)
|
||||||
#define STR_HEAP_SIZE(str) (RSTRING(str)->as.heap.aux.capa + TERM_LEN(str))
|
#define STR_HEAP_SIZE(str) (RSTRING(str)->as.heap.aux.capa + TERM_LEN(str))
|
||||||
|
|
||||||
#define STR_ENC_GET(str) rb_enc_from_index(ENCODING_GET(str))
|
#define STR_ENC_GET(str) get_encoding(str)
|
||||||
|
|
||||||
rb_encoding *rb_enc_get_from_index(int index);
|
rb_encoding *rb_enc_get_from_index(int index);
|
||||||
|
|
||||||
|
@ -155,6 +155,12 @@ get_actual_encoding(const int encidx, VALUE str)
|
||||||
return rb_enc_from_index(encidx);
|
return rb_enc_from_index(encidx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static rb_encoding *
|
||||||
|
get_encoding(VALUE str)
|
||||||
|
{
|
||||||
|
return get_actual_encoding(ENCODING_GET(str), str);
|
||||||
|
}
|
||||||
|
|
||||||
static int fstring_cmp(VALUE a, VALUE b);
|
static int fstring_cmp(VALUE a, VALUE b);
|
||||||
|
|
||||||
static st_table* frozen_strings;
|
static st_table* frozen_strings;
|
||||||
|
|
|
@ -229,6 +229,7 @@ class TestM17N < Test::Unit::TestCase
|
||||||
STR_WITHOUT_BOM = "\u3042".freeze
|
STR_WITHOUT_BOM = "\u3042".freeze
|
||||||
STR_WITH_BOM = "\uFEFF\u3042".freeze
|
STR_WITH_BOM = "\uFEFF\u3042".freeze
|
||||||
bug8940 = '[ruby-core:59757] [Bug #8940]'
|
bug8940 = '[ruby-core:59757] [Bug #8940]'
|
||||||
|
bug9415 = '[ruby-dev:47895] [Bug #9415]'
|
||||||
%w/UTF-16 UTF-32/.each do |enc|
|
%w/UTF-16 UTF-32/.each do |enc|
|
||||||
%w/BE LE/.each do |endian|
|
%w/BE LE/.each do |endian|
|
||||||
bom = "\uFEFF".encode("#{enc}#{endian}").force_encoding(enc)
|
bom = "\uFEFF".encode("#{enc}#{endian}").force_encoding(enc)
|
||||||
|
@ -242,6 +243,14 @@ class TestM17N < Test::Unit::TestCase
|
||||||
assert_normal_exit("#{bom.b.dump}.force_encoding('#{enc}').inspect", bug8940)
|
assert_normal_exit("#{bom.b.dump}.force_encoding('#{enc}').inspect", bug8940)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
define_method("test_utf_16_32_codepoints(#{enc}#{endian})") do
|
||||||
|
assert_equal([0xFEFF], bom.codepoints, bug9415)
|
||||||
|
end
|
||||||
|
|
||||||
|
define_method("test_utf_16_32_ord(#{enc}#{endian})") do
|
||||||
|
assert_equal(0xFEFF, bom.ord, bug9415)
|
||||||
|
end
|
||||||
|
|
||||||
define_method("test_utf_16_32_inspect(#{enc}#{endian}-BOM)") do
|
define_method("test_utf_16_32_inspect(#{enc}#{endian}-BOM)") do
|
||||||
s = STR_WITH_BOM.encode(enc + endian)
|
s = STR_WITH_BOM.encode(enc + endian)
|
||||||
# When a UTF-16/32 string has a BOM,
|
# When a UTF-16/32 string has a BOM,
|
||||||
|
|
Загрузка…
Ссылка в новой задаче