summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--MANIFEST1
-rw-r--r--lib/erb.rb2
-rw-r--r--test/erb/test_erb.rb40
4 files changed, 49 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index d058adb..5b5b541 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Sat Feb 28 10:31:03 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+
+ * 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 <matz@ruby-lang.org>
* eval.c (proc_invoke): no orphan block check is needed when pcall
diff --git a/MANIFEST b/MANIFEST
index 70cee12..e7872bd 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 4e3aaf4..44529bf 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 0000000..8641197
--- /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