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

fix %% line bug. [ruby-core:17491]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@17881 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
seki 2008-07-04 15:40:33 +00:00
parent 35df0ea099
commit 447e3c3702
3 changed files with 25 additions and 4 deletions

View file

@ -1,3 +1,9 @@
Sat Jul 5 00:33:08 2008 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* lib/erb.rb (PercentScanner#scan): fix %% line bug. [ruby-core:17491]
* test/erb/test_erb.rb (test_percent): ditto.
Sat Jul 5 00:31:53 2008 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* ext/win32ole/win32ole.c (d2time): fix the bug of VT_DATE

View file

@ -427,7 +427,7 @@ class ERB
Scanner.regist_scanner(SimpleScanner2, nil, false)
class PercentScanner < Scanner # :nodoc:
def scan
def scan(&blk)
stag_reg = /(.*?)(^%%|^%|<%%|<%=|<%#|<%|\z)/m
etag_reg = /(.*?)(%%>|%>|\z)/m
scanner = StringScanner.new(@src)
@ -437,11 +437,24 @@ class ERB
elem = scanner[2]
if elem == '%%'
elem = '%'
yield('%')
inline_scan(scanner.scan(/.*?(\n|\z)/), &blk)
elsif elem == '%'
elem = PercentLine.new(scanner.scan(/.*?(\n|\z)/).chomp)
yield(PercentLine.new(scanner.scan(/.*?(\n|\z)/).chomp))
else
yield(elem)
end
yield(elem)
end
end
def inline_scan(line)
stag_reg = /(.*?)(<%%|<%=|<%#|<%|\z)/m
etag_reg = /(.*?)(%%>|%>|\z)/m
scanner = StringScanner.new(line)
while ! scanner.eos?
scanner.scan(@stag ? etag_reg : stag_reg)
yield(scanner[1])
yield(scanner[2])
end
end
end

View file

@ -209,11 +209,13 @@ EOS
n.times do |i|%>
%% %%><%%<%= i%><%
end%>
%%%
EOS
ans = <<EOS
%
% %%><%0
% %%><%1
%%
EOS
assert_equal(ans, ERB.new(src, nil, '%').result)
end