Skip to content

Commit 3cf6122

Browse files
committed
Fix ActionView backtrace filtering on Ruby 3.4+
1 parent fee72c3 commit 3cf6122

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

railties/lib/rails/backtrace_cleaner.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
module Rails
77
class BacktraceCleaner < ActiveSupport::BacktraceCleaner # :nodoc:
88
APP_DIRS_PATTERN = /\A(?:\.\/)?(?:app|config|lib|test|\(\w*\))/
9-
RENDER_TEMPLATE_PATTERN = /:in `.*_\w+_{2,3}\d+_\d+'/
9+
RENDER_TEMPLATE_PATTERN = /:in [`'].*_\w+_{2,3}\d+_\d+'/
1010

1111
def initialize
1212
super

railties/test/backtrace_cleaner_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ def setup
4343
assert_equal "app/views/application/index.html.erb:4", result[0]
4444
end
4545

46+
test "#clean should omit ActionView template methods names on Ruby 3.4+" do
47+
method_name = ActionView::Template.new(nil, "app/views/application/index.html.erb", nil, locals: []).send :method_name
48+
backtrace = [ "app/views/application/index.html.erb:4:in 'block in #{method_name}'"]
49+
result = @cleaner.clean(backtrace, :all)
50+
assert_equal "app/views/application/index.html.erb:4", result[0]
51+
end
52+
4653
test "#clean_frame should consider traces from irb lines as User code" do
4754
assert_equal "(irb):1", @cleaner.clean_frame("(irb):1")
4855
assert_nil @cleaner.clean_frame("/Path/to/rails/railties/lib/rails/commands/console.rb:77:in `start'")
@@ -67,4 +74,10 @@ def setup
6774
frame = @cleaner.clean_frame("app/views/application/index.html.erb:4:in `block in #{method_name}'", :all)
6875
assert_equal "app/views/application/index.html.erb:4", frame
6976
end
77+
78+
test "#clean_frame should omit ActionView template methods names on Ruby 3.4+" do
79+
method_name = ActionView::Template.new(nil, "app/views/application/index.html.erb", nil, locals: []).send :method_name
80+
frame = @cleaner.clean_frame("app/views/application/index.html.erb:4:in 'block in #{method_name}'", :all)
81+
assert_equal "app/views/application/index.html.erb:4", frame
82+
end
7083
end

0 commit comments

Comments
 (0)