Bug #14257
closedthe chomp option removes newlines in additon to the provided separator for String#each_line and String#lines
Description
I'm not entirely sure this is a bug but I had a hard time finding anything that indicated that the change was on purpose.
The chomp
option would remove the provided separator from each line. Now it does that and it also removes newlines.
2.4
> "a b c d\n".lines(' ', chomp: true)
=> ["a", "b", "c", "d\n"]
2.5
> "a b c d\n".lines(' ', chomp: true)
=> ["a", "b", "c", "d"]
Updated by shevegen (Robert A. Heiler) almost 7 years ago
I wanted to have a look but to my surprise, the documentation at:
https://ruby-doc.org/core-2.5.0/String.html#method-i-lines
does not seem to indicate more than one agument to this method?
Either way, could someone perhaps add a few examples to this
method, on the documentation, perhaps also including the
lines(' ', chomp: true) variant? Because as it presently is,
I can't seem to find the chomp: true part. Perhaps it was added
only somewhat recently.
Updated by nobu (Nobuyoshi Nakada) almost 7 years ago
- Status changed from Open to Closed
Applied in changeset trunk|r61513.
string.c: chomp rs at the end
- string.c (rb_str_enumerate_lines): should chomp record separator
only, but not a newline, at the end of the receiver as well as
middle, if the separator is given.
[ruby-core:84552] [Bug #14257]
Updated by nobu (Nobuyoshi Nakada) almost 7 years ago
- Backport changed from 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN to 2.3: DONTNEED, 2.4: DONTNEED, 2.5: REQUIRED
Updated by naruse (Yui NARUSE) almost 7 years ago
- Backport changed from 2.3: DONTNEED, 2.4: DONTNEED, 2.5: REQUIRED to 2.3: DONTNEED, 2.4: DONTNEED, 2.5: DONE
ruby_2_5 r61628 merged revision(s) 61513.
Updated by nobu (Nobuyoshi Nakada) almost 7 years ago
- Backport changed from 2.3: DONTNEED, 2.4: DONTNEED, 2.5: DONE to 2.3: DONTNEED, 2.4: DONTNEED, 2.5: REQUIRED
Sorry, r61636 is needed too.
Huge RS with chomp
option could cause a SEGV.
Updated by naruse (Yui NARUSE) over 6 years ago
- Backport changed from 2.3: DONTNEED, 2.4: DONTNEED, 2.5: REQUIRED to 2.3: DONTNEED, 2.4: DONTNEED, 2.5: DONE
ruby_2_5 r62421 merged revision(s) 61636.