1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

erb.rb: Allow trimming carriage return

when trim_mode is "<>", for Windows environments.

[Bug #11464]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58823 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
k0kubun 2017-05-20 16:50:33 +00:00
parent a6986f10d0
commit 040f275690
2 changed files with 7 additions and 2 deletions

View file

@ -392,7 +392,7 @@ class ERB
@scan_reg = /(.*?)(%>\n|#{(stags + etags).join('|')}|\n|\z)/m
@scan_line = self.method(:trim_line1)
elsif @trim_mode == '<>'
@scan_reg = /(.*?)(%>\n|#{(stags + etags).join('|')}|\n|\z)/m
@scan_reg = /(.*?)(%>\r?\n|#{(stags + etags).join('|')}|\n|\z)/m
@scan_line = self.method(:trim_line2)
elsif @trim_mode == '-'
@scan_reg = /(.*?)(^[ \t]*<%\-|<%\-|-%>\n|-%>|#{(stags + etags).join('|')}|\z)/m
@ -457,7 +457,7 @@ class ERB
tokens.each do |token|
next if token.empty?
head = token unless head
if token == "%>\n"
if token == "%>\n" || token == "%>\r\n"
yield('%>')
if is_erb_stag?(head)
yield(:cr)

View file

@ -197,6 +197,11 @@ EOS
assert_equal(ans, erb.result)
end
def test_trim_line2_with_carriage_return
erb = @erb.new("<% 3.times do %>\r\nline\r\n<% end %>\r\n", nil, '<>')
assert_equal("line\r\n" * 3, erb.result)
end
class Foo; end
def test_def_class