summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-29 12:19:03 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-29 12:19:03 +0000
commit634a48c5c1eba9d0d663759faf0c2156007a403a (patch)
treedf4dce75da3828d61b469e95f6cd2fb606c5970c /string.c
parent18640bf9f0fd60dfa116a65558af6e9314cda491 (diff)
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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61513 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/string.c b/string.c
index 88516eb7c4..92995d1ce5 100644
--- a/string.c
+++ b/string.c
@@ -8012,7 +8012,12 @@ rb_str_enumerate_lines(int argc, VALUE *argv, VALUE str, VALUE ary)
if (subptr != pend) {
if (chomp) {
- pend = chomp_newline(subptr, pend, enc);
+ if (rsnewline) {
+ pend = chomp_newline(subptr, pend, enc);
+ }
+ else if (memcmp(pend - rslen, rsptr, rslen) == 0) {
+ pend -= rslen;
+ }
}
line = rb_str_subseq(str, subptr - ptr, pend - subptr);
ENUM_ELEM(ary, line);