diff --git a/ChangeLog b/ChangeLog index d058adbea7..5b5b541e58 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Sat Feb 28 10:31:03 2004 Masatoshi SEKI + + * MANIFEST: add test_erb.rb + + * lib/erb.rb, test/erb/test_erb.rb: don't forget filename, + if both filename and safe_level given. [ruby-dev:23050] + Fri Feb 27 20:37:09 2004 Yukihiro Matsumoto * eval.c (proc_invoke): no orphan block check is needed when pcall diff --git a/MANIFEST b/MANIFEST index 70cee12ccd..e7872bdc1f 100644 --- a/MANIFEST +++ b/MANIFEST @@ -772,6 +772,7 @@ test/drb/ut_large.rb test/drb/ut_port.rb test/drb/ut_safe1.rb test/drb/ut_timerholder.rb +test/erb/test_erb.rb test/fileutils/fileasserts.rb test/fileutils/test_fileutils.rb test/fileutils/test_nowrite.rb diff --git a/lib/erb.rb b/lib/erb.rb index 4e3aaf4a86..44529bf325 100644 --- a/lib/erb.rb +++ b/lib/erb.rb @@ -414,7 +414,7 @@ class ERB if @safe_level th = Thread.start { $SAFE = @safe_level - eval(@src, b) + eval(@src, b, (@filename || '(erb)'), 1) } return th.value else diff --git a/test/erb/test_erb.rb b/test/erb/test_erb.rb new file mode 100644 index 0000000000..8641197414 --- /dev/null +++ b/test/erb/test_erb.rb @@ -0,0 +1,40 @@ +require 'test/unit' +require 'erb' + +class TestERB < Test::Unit::TestCase + class MyError < RuntimeError ; end + + def test_without_filename + erb = ERB.new("<% raise ::TestERB::MyError %>") + e = assert_raise(MyError) { + erb.result + } + assert_equal("(erb):1", e.backtrace[0]) + end + + def test_with_filename + erb = ERB.new("<% raise ::TestERB::MyError %>") + erb.filename = "test filename" + e = assert_raise(MyError) { + erb.result + } + assert_equal("test filename:1", e.backtrace[0]) + end + + def test_without_filename_with_safe_level + erb = ERB.new("<% raise ::TestERB::MyError %>", 1) + e = assert_raise(MyError) { + erb.result + } + assert_equal("(erb):1", e.backtrace[0]) + end + + def test_with_filename_and_safe_level + erb = ERB.new("<% raise ::TestERB::MyError %>", 1) + erb.filename = "test filename" + e = assert_raise(MyError) { + erb.result + } + assert_equal("test filename:1", e.backtrace[0]) + end +end