зеркало из https://github.com/github/ruby.git
[ruby/stringio] [Bug #19389] Fix chomping with longer separator
https://github.com/ruby/stringio/commit/eb322a9716
This commit is contained in:
Родитель
8429134d0d
Коммит
21dced8b01
|
@ -1340,8 +1340,9 @@ strio_getline(struct getline_arg *arg, struct StringIO *ptr)
|
|||
str = strio_substr(ptr, ptr->pos, e - s - w, enc);
|
||||
}
|
||||
else {
|
||||
if (n < e - s) {
|
||||
if (e - s < 1024) {
|
||||
if (n < e - s + arg->chomp) {
|
||||
/* unless chomping, RS at the end does not matter */
|
||||
if (e - s < 1024 || n == e - s) {
|
||||
for (p = s; p + n <= e; ++p) {
|
||||
if (MEMCMP(p, RSTRING_PTR(str), char, n) == 0) {
|
||||
e = p + n;
|
||||
|
|
|
@ -99,6 +99,8 @@ class TestStringIO < Test::Unit::TestCase
|
|||
assert_equal("def\n", stringio.gets("", chomp: true))
|
||||
|
||||
assert_string("", Encoding::UTF_8, StringIO.new("\n").gets(chomp: true))
|
||||
|
||||
assert_equal("", StringIO.new("ab").gets("ab", chomp: true))
|
||||
end
|
||||
|
||||
def test_gets_chomp_eol
|
||||
|
|
Загрузка…
Ссылка в новой задаче