summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-01-28 21:59:54 +0900
committergit <svn-admin@ruby-lang.org>2023-01-28 13:00:08 +0000
commit21dced8b01823a991829b66ffdc8ffc635965c76 (patch)
tree790fb5251357df26610e9916191f05b1606a1f27 /ext
parent8429134d0d942f89fa022af38e065eb33c83523a (diff)
[ruby/stringio] [Bug #19389] Fix chomping with longer separator
https://github.com/ruby/stringio/commit/eb322a9716
Diffstat (limited to 'ext')
-rw-r--r--ext/stringio/stringio.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index bc2d7a8ccc..52a7072231 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -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;