mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
merge revision(s) 5b1bf8dd2d: [Backport #16099]
UTF LE is fixed at least the first 2 bytes * io.c (io_strip_bom): if the first 2 bytes are 0xFF0xFE, it should be a little-endian UTF, 16 or 32. [Bug #16099] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_5@67772 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ef626cd09c
commit
f8efd7f9e8
4 changed files with 9 additions and 12 deletions
3
io.c
3
io.c
|
|
@ -6025,13 +6025,10 @@ io_strip_bom(VALUE io)
|
||||||
return ENCINDEX_UTF_32LE;
|
return ENCINDEX_UTF_32LE;
|
||||||
}
|
}
|
||||||
rb_io_ungetbyte(io, b4);
|
rb_io_ungetbyte(io, b4);
|
||||||
rb_io_ungetbyte(io, b3);
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
rb_io_ungetbyte(io, b3);
|
rb_io_ungetbyte(io, b3);
|
||||||
return ENCINDEX_UTF_16LE;
|
return ENCINDEX_UTF_16LE;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
rb_io_ungetbyte(io, b2);
|
rb_io_ungetbyte(io, b2);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ class TestFile < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_bom_32le
|
def test_bom_32le
|
||||||
assert_bom(["\xFF\xFE\0", "\0"], __method__)
|
assert_bom(["\xFF", "\xFE\0\0"], __method__)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_truncate_wbuf
|
def test_truncate_wbuf
|
||||||
|
|
|
||||||
|
|
@ -2082,14 +2082,14 @@ EOT
|
||||||
|
|
||||||
def test_strip_bom
|
def test_strip_bom
|
||||||
with_tmpdir {
|
with_tmpdir {
|
||||||
text = "\uFEFFa"
|
text = "\uFEFF\u0100a"
|
||||||
stripped = "a"
|
stripped = "\u0100a"
|
||||||
%w/UTF-8 UTF-16BE UTF-16LE UTF-32BE UTF-32LE/.each do |name|
|
%w/UTF-8 UTF-16BE UTF-16LE UTF-32BE UTF-32LE/.each do |name|
|
||||||
path = '%s-bom.txt' % name
|
path = '%s-bom.txt' % name
|
||||||
content = text.encode(name)
|
content = text.encode(name)
|
||||||
generate_file(path, content)
|
generate_file(path, content)
|
||||||
result = File.read(path, mode: 'rb:BOM|UTF-8')
|
result = File.read(path, mode: 'rb:BOM|UTF-8')
|
||||||
assert_equal(content[1].force_encoding("ascii-8bit"),
|
assert_equal(content[1..-1].force_encoding("ascii-8bit"),
|
||||||
result.force_encoding("ascii-8bit"))
|
result.force_encoding("ascii-8bit"))
|
||||||
result = File.read(path, mode: 'rb:BOM|UTF-8:UTF-8')
|
result = File.read(path, mode: 'rb:BOM|UTF-8:UTF-8')
|
||||||
assert_equal(Encoding::UTF_8, result.encoding)
|
assert_equal(Encoding::UTF_8, result.encoding)
|
||||||
|
|
@ -2099,10 +2099,10 @@ EOT
|
||||||
bug3407 = '[ruby-core:30641]'
|
bug3407 = '[ruby-core:30641]'
|
||||||
path = 'UTF-8-bom.txt'
|
path = 'UTF-8-bom.txt'
|
||||||
result = File.read(path, encoding: 'BOM|UTF-8')
|
result = File.read(path, encoding: 'BOM|UTF-8')
|
||||||
assert_equal("a", result.force_encoding("ascii-8bit"), bug3407)
|
assert_equal(stripped.b, result.force_encoding("ascii-8bit"), bug3407)
|
||||||
|
|
||||||
bug8323 = '[ruby-core:54563] [Bug #8323]'
|
bug8323 = '[ruby-core:54563] [Bug #8323]'
|
||||||
expected = "a\xff".force_encoding("utf-8")
|
expected = (stripped.b + "\xff").force_encoding("utf-8")
|
||||||
open(path, 'ab') {|f| f.write("\xff")}
|
open(path, 'ab') {|f| f.write("\xff")}
|
||||||
result = File.read(path, encoding: 'BOM|UTF-8')
|
result = File.read(path, encoding: 'BOM|UTF-8')
|
||||||
assert_not_predicate(result, :valid_encoding?, bug8323)
|
assert_not_predicate(result, :valid_encoding?, bug8323)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#define RUBY_VERSION "2.5.6"
|
#define RUBY_VERSION "2.5.6"
|
||||||
#define RUBY_RELEASE_DATE "2019-08-27"
|
#define RUBY_RELEASE_DATE "2019-08-27"
|
||||||
#define RUBY_PATCHLEVEL 190
|
#define RUBY_PATCHLEVEL 191
|
||||||
|
|
||||||
#define RUBY_RELEASE_YEAR 2019
|
#define RUBY_RELEASE_YEAR 2019
|
||||||
#define RUBY_RELEASE_MONTH 8
|
#define RUBY_RELEASE_MONTH 8
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue