summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-03 01:18:47 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-03 01:18:47 +0000
commit0eb420cc78e5027a2611057a535fd255e87723fb (patch)
tree5e1228276c1167b664d34ec4512554eced7b666a
parentd16f9a75df7076a69f94c64608aead438f3e7ffe (diff)
* lib/erb.rb (ERB::Compiler::TrimScanner#scan_line): Fix a bug
where tokens are not yilelded one by one. (ERB::Compiler::TrimScanner#explicit_trim_line): Fix without- strscan problems. [ruby_core:17028]. * test/erb/test_erb.rb (TestERBCore#_test_01) (TestERBCore#test_02_safe_04): The expected value should come first for assert_equal(). (TestERBCoreWOStrScan): Add test class for without-strscan. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_7@16764 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog12
-rw-r--r--lib/erb.rb41
-rw-r--r--test/erb/test_erb.rb65
-rw-r--r--version.h8
4 files changed, 76 insertions, 50 deletions
diff --git a/ChangeLog b/ChangeLog
index 72bb59fe61..1a638fdf05 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+Tue Jun 3 10:16:40 2008 Akinori MUSHA <knu@iDaemons.org>
+
+ * lib/erb.rb (ERB::Compiler::TrimScanner#scan_line): Fix a bug
+ where tokens are not yilelded one by one.
+ (ERB::Compiler::TrimScanner#explicit_trim_line): Fix without-
+ strscan problems. [ruby_core:17028].
+
+ * test/erb/test_erb.rb (TestERBCore#_test_01)
+ (TestERBCore#test_02_safe_04): The expected value should come
+ first for assert_equal().
+ (TestERBCoreWOStrScan): Add test class for without-strscan.
+
Mon Jun 2 19:47:16 2008 Akinori MUSHA <knu@iDaemons.org>
* lib/delegate.rb (DelegateClass, Delegator#respond_to?):
diff --git a/lib/erb.rb b/lib/erb.rb
index 3cfbc11c30..a37832dafe 100644
--- a/lib/erb.rb
+++ b/lib/erb.rb
@@ -327,16 +327,18 @@ class ERB
end
def scan_line(line)
- line.scan(/(.*?)(<%%|%%>|<%=|<%#|<%|%>|\n|\z)/m) do |token|
- next if token.empty?
- yield(token)
+ line.scan(/(.*?)(<%%|%%>|<%=|<%#|<%|%>|\n|\z)/m) do |tokens|
+ tokens.each do |token|
+ next if token.empty?
+ yield(token)
+ end
end
end
def trim_line1(line)
line.scan(/(.*?)(<%%|%%>|<%=|<%#|<%|%>\n|%>|\n|\z)/m) do |tokens|
tokens.each do |token|
- next if token.empty?
+ next if token.empty?
if token == "%>\n"
yield('%>')
yield(:cr)
@@ -355,7 +357,7 @@ class ERB
head = token unless head
if token == "%>\n"
yield('%>')
- if is_erb_stag?(head)
+ if is_erb_stag?(head)
yield(:cr)
else
yield("\n")
@@ -369,21 +371,22 @@ class ERB
end
end
- ExplicitTrimRegexp = /(^[ \t]*<%-)|(-%>\n?\z)|(<%-)|(-%>)|(<%%)|(%%>)|(<%=)|(<%#)|(<%)|(%>)|(\n)/
def explicit_trim_line(line)
- line.split(ExplicitTrimRegexp).each do |token|
- next if token.empty?
- if @stag.nil? && /[ \t]*<%-/ =~ token
- yield('<%')
- elsif @stag && /-%>\n/ =~ token
- yield('%>')
- yield(:cr)
- elsif @stag && token == '-%>'
- yield('%>')
- else
- yield(token)
- end
- end
+ line.scan(/(.*?)(^[ \t]*<%\-|<%\-|<%%|%%>|<%=|<%#|<%|-%>\n|-%>|%>|\z)/m) do |tokens|
+ tokens.each do |token|
+ next if token.empty?
+ if @stag.nil? && /[ \t]*<%-/ =~ token
+ yield('<%')
+ elsif @stag && token == "-%>\n"
+ yield('%>')
+ yield(:cr)
+ elsif @stag && token == '-%>'
+ yield('%>')
+ else
+ yield(token)
+ end
+ end
+ end
end
ERB_STAG = %w(<%= <%# <%)
diff --git a/test/erb/test_erb.rb b/test/erb/test_erb.rb
index 5815bdb3c0..48bd7b50b9 100644
--- a/test/erb/test_erb.rb
+++ b/test/erb/test_erb.rb
@@ -44,26 +44,26 @@ class TestERBCore < Test::Unit::TestCase
@erb = ERB
end
- def test_01
- _test_01(nil)
- _test_01(0)
- _test_01(1)
- _test_01(2)
- _test_01(3)
+ def test_core
+ _test_core(nil)
+ _test_core(0)
+ _test_core(1)
+ _test_core(2)
+ _test_core(3)
end
- def _test_01(safe)
+ def _test_core(safe)
erb = @erb.new("hello")
- assert_equal(erb.result, "hello")
+ assert_equal("hello", erb.result)
erb = @erb.new("hello", safe, 0)
- assert_equal(erb.result, "hello")
+ assert_equal("hello", erb.result)
erb = @erb.new("hello", safe, 1)
- assert_equal(erb.result, "hello")
+ assert_equal("hello", erb.result)
erb = @erb.new("hello", safe, 2)
- assert_equal(erb.result, "hello")
+ assert_equal("hello", erb.result)
src = <<EOS
%% hi
@@ -157,14 +157,14 @@ EOS
assert_equal(ans, erb.result)
end
- def test_02_safe_04
+ def test_safe_04
erb = @erb.new('<%=$SAFE%>', 4)
- assert_equal(erb.result(TOPLEVEL_BINDING.taint), '4')
+ assert_equal('4', erb.result(TOPLEVEL_BINDING.taint))
end
class Foo; end
- def test_03_def_class
+ def test_def_class
erb = @erb.new('hello')
cls = erb.def_class
assert_equal(Object, cls.superclass)
@@ -177,7 +177,7 @@ EOS
assert(cls.new.respond_to?('erb'))
end
- def test_04_percent
+ def test_percent
src = <<EOS
%n = 1
<%= n%>
@@ -218,26 +218,24 @@ EOS
assert_equal(ans, ERB.new(src, nil, '%').result)
end
- class Bar; end
-
- def test_05_def_method
- assert(! Bar.new.respond_to?('hello'))
- Bar.module_eval do
+ def test_def_method
+ klass = Class.new
+ klass.module_eval do
extend ERB::DefMethod
fname = File.join(File.dirname(File.expand_path(__FILE__)), 'hello.erb')
def_erb_method('hello', fname)
end
- assert(Bar.new.respond_to?('hello'))
+ assert(klass.new.respond_to?('hello'))
- assert(! Bar.new.respond_to?('hello_world'))
+ assert(! klass.new.respond_to?('hello_world'))
erb = @erb.new('hello, world')
- Bar.module_eval do
+ klass.module_eval do
def_erb_method('hello_world', erb)
end
- assert(Bar.new.respond_to?('hello_world'))
+ assert(klass.new.respond_to?('hello_world'))
end
- def test_06_escape
+ def test_escape
src = <<EOS
1.<%% : <%="<%%"%>
2.%%> : <%="%%>"%>
@@ -274,7 +272,7 @@ EOS
assert_equal(ans, ERB.new(src, nil, '%').result)
end
- def test_07_keep_lineno
+ def test_keep_lineno
src = <<EOS
Hello,
% x = "World"
@@ -378,7 +376,7 @@ EOS
end
end
- def test_08_explicit
+ def test_explicit
src = <<EOS
<% x = %w(hello world) -%>
NotSkip <%- y = x -%> NotSkip
@@ -411,3 +409,16 @@ EOS
assert_equal(ans, ERB.new(src, nil, '-%').result)
end
end
+
+class TestERBCoreWOStrScan < TestERBCore
+ def setup
+ @save_map = ERB::Compiler::Scanner.instance_variable_get('@scanner_map')
+ map = {[nil, false]=>ERB::Compiler::SimpleScanner}
+ ERB::Compiler::Scanner.instance_variable_set('@scanner_map', map)
+ super
+ end
+
+ def teardown
+ ERB::Compiler::Scanner.instance_variable_set('@scanner_map', @save_map)
+ end
+end
diff --git a/version.h b/version.h
index 191cde7a98..bfda2b1cc6 100644
--- a/version.h
+++ b/version.h
@@ -1,15 +1,15 @@
#define RUBY_VERSION "1.8.7"
-#define RUBY_RELEASE_DATE "2008-06-02"
+#define RUBY_RELEASE_DATE "2008-06-03"
#define RUBY_VERSION_CODE 187
-#define RUBY_RELEASE_CODE 20080602
-#define RUBY_PATCHLEVEL 1
+#define RUBY_RELEASE_CODE 20080603
+#define RUBY_PATCHLEVEL 2
#define RUBY_VERSION_MAJOR 1
#define RUBY_VERSION_MINOR 8
#define RUBY_VERSION_TEENY 7
#define RUBY_RELEASE_YEAR 2008
#define RUBY_RELEASE_MONTH 6
-#define RUBY_RELEASE_DAY 2
+#define RUBY_RELEASE_DAY 3
#ifdef RUBY_EXTERN
RUBY_EXTERN const char ruby_version[];