зеркало из https://github.com/github/ruby.git
erb.rb: Allow trimming CR in all trim_modes
to unify a behavior with r58823 and r58825. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58826 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
b82ed2ce61
Коммит
64c914706e
5
NEWS
5
NEWS
|
@ -88,6 +88,11 @@ with all sufficient information, see the ChangeLog file or Redmine
|
|||
* New constants:
|
||||
* RbConfig::LIMITS is added to provide the limits of C types.
|
||||
|
||||
* ERB
|
||||
* Carriage returns are changed to be trimmed properly if trim_mode is specified
|
||||
and used. Duplicated newlines will be removed on Windows.
|
||||
[Bug #5339] [Bug #11464]
|
||||
|
||||
=== Compatibility issues (excluding feature bug fixes)
|
||||
|
||||
* Net::HTTP
|
||||
|
|
|
@ -389,7 +389,7 @@ class ERB
|
|||
@trim_mode = trim_mode
|
||||
@percent = percent
|
||||
if @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_line1)
|
||||
elsif @trim_mode == '<>'
|
||||
@scan_reg = /(.*?)(%>\r?\n|#{(stags + etags).join('|')}|\n|\z)/m
|
||||
|
@ -441,7 +441,7 @@ class ERB
|
|||
line.scan(@scan_reg) do |tokens|
|
||||
tokens.each do |token|
|
||||
next if token.empty?
|
||||
if token == "%>\n"
|
||||
if token == "%>\n" || token == "%>\r\n"
|
||||
yield('%>')
|
||||
yield(:cr)
|
||||
else
|
||||
|
|
|
@ -197,6 +197,14 @@ EOS
|
|||
assert_equal(ans, erb.result)
|
||||
end
|
||||
|
||||
def test_trim_line1_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)
|
||||
|
||||
erb = @erb.new("<% 3.times do %>\r\nline\r\n<% end %>\r\n", nil, '%>')
|
||||
assert_equal("line\r\n" * 3, 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)
|
||||
|
|
Загрузка…
Ссылка в новой задаче