summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-05 20:39:03 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-05 20:39:03 +0000
commit311d499f5e34c9ad65687d241f65c654393ad73b (patch)
treecadbae7f91be14f7947bb6372034888aa9d91aef
parentba5b713682bb47244324da2dcd5c879da9288319 (diff)
merge revision(s) 61513: [Backport #14257]
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/branches/ruby_2_5@61628 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--string.c7
-rw-r--r--test/ruby/test_string.rb4
-rw-r--r--version.h6
3 files changed, 13 insertions, 4 deletions
diff --git a/string.c b/string.c
index 30d57b5df4..6492a2a7fc 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);
diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb
index e88746dc55..b0c6e447eb 100644
--- a/test/ruby/test_string.rb
+++ b/test/ruby/test_string.rb
@@ -1119,6 +1119,10 @@ CODE
res = []
S("\r\n").each_line(chomp: true) {|x| res << x}
assert_equal([S("")], res)
+
+ res = []
+ S("a\n b\n").each_line(" ", chomp: true) {|x| res << x}
+ assert_equal([S("a\n"), S("b\n")], res)
end
def test_lines
diff --git a/version.h b/version.h
index 7381fc70ba..ca59f6ddeb 100644
--- a/version.h
+++ b/version.h
@@ -1,10 +1,10 @@
#define RUBY_VERSION "2.5.0"
-#define RUBY_RELEASE_DATE "2018-01-04"
-#define RUBY_PATCHLEVEL 6
+#define RUBY_RELEASE_DATE "2018-01-06"
+#define RUBY_PATCHLEVEL 7
#define RUBY_RELEASE_YEAR 2018
#define RUBY_RELEASE_MONTH 1
-#define RUBY_RELEASE_DAY 4
+#define RUBY_RELEASE_DAY 6
#include "ruby/version.h"