Skip to content

Commit cff28a1

Browse files
nobupranjalithakur
andcommitted
Skip chompped record separator
Fix #218. Co-Authored-By: Pranjali Thakur <pranjali@depthfirst.com>
1 parent 49dddcd commit cff28a1

3 files changed

Lines changed: 8 additions & 2 deletions

File tree

‎ext/java/org/jruby/ext/stringio/StringIO.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,8 @@ private IRubyObject getline(ThreadContext context, final IRubyObject rs, int lim
959959
p = rsByteList.getBegin();
960960
bm_init_skip(skip, rsBytes, p, n);
961961
if ((pos2 = bm_search(rsBytes, p, n, stringBytes, s, e - s, skip)) >= 0) {
962-
e = s + pos2 + (chomp ? 0 : n);
962+
e = s + pos2 + n;
963+
if (chomp) w = n;
963964
}
964965
}
965966
}

‎ext/stringio/stringio.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1447,7 +1447,8 @@ strio_getline(struct getline_arg *arg, struct StringIO *ptr)
14471447
p = RSTRING_PTR(str);
14481448
bm_init_skip(skip, p, n);
14491449
if ((pos = bm_search(p, n, s, e - s, skip)) >= 0) {
1450-
e = s + pos + (arg->chomp ? 0 : n);
1450+
e = s + pos + n;
1451+
if (arg->chomp) w = n;
14511452
}
14521453
}
14531454
}

‎test/stringio/test_stringio.rb‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ def test_gets_chomp
168168
assert_string("", Encoding::UTF_8, StringIO.new("\n").gets(chomp: true))
169169

170170
assert_equal("", StringIO.new("ab").gets("ab", chomp: true))
171+
172+
sio = StringIO.new("abcde\r\n" "fghij\r\n" + "z"*1024)
173+
assert_equal("abcde", sio.gets("\r\n", chomp: true))
174+
assert_equal("fghij", sio.gets("\r\n", chomp: true))
171175
end
172176

173177
def test_gets_chomp_eol

0 commit comments

Comments
 (0)