summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@ruby-lang.org>2023-03-21 13:56:55 +0900
committernagachika <nagachika@ruby-lang.org>2023-03-21 13:56:55 +0900
commit1d24a931c458c93463da1d5885f33edef3677cc2 (patch)
treeaf9e2f76a3a268c5051897fb3f36aae80fb6a841
parent8322413e58bdce11136c33aec3e0611b2b135cd8 (diff)
merge revision(s) 21dced8b01823a991829b66ffdc8ffc635965c76: [Backport #19389]
[ruby/stringio] [Bug #19389] Fix chomping with longer separator https://github.com/ruby/stringio/commit/eb322a9716 --- ext/stringio/stringio.c | 5 +++-- test/stringio/test_stringio.rb | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-)
-rw-r--r--ext/stringio/stringio.c5
-rw-r--r--test/stringio/test_stringio.rb2
-rw-r--r--version.h2
3 files changed, 6 insertions, 3 deletions
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index 8df07e80f6..7c34164d31 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -1233,8 +1233,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 + (arg->chomp ? 0 : n);
diff --git a/test/stringio/test_stringio.rb b/test/stringio/test_stringio.rb
index e0b4504b54..e91a625488 100644
--- a/test/stringio/test_stringio.rb
+++ b/test/stringio/test_stringio.rb
@@ -99,6 +99,8 @@ class TestStringIO < Test::Unit::TestCase
assert_equal("def", 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
diff --git a/version.h b/version.h
index c1ba27e3b8..410987229f 100644
--- a/version.h
+++ b/version.h
@@ -11,7 +11,7 @@
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY 4
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 199
+#define RUBY_PATCHLEVEL 200
#define RUBY_RELEASE_YEAR 2023
#define RUBY_RELEASE_MONTH 3