diff --git a/activesupport/lib/active_support/backtrace_cleaner.rb b/activesupport/lib/active_support/backtrace_cleaner.rb index ad80b8855f3fa6c9a68fc8b71cfd43f4bd168708..405db9a6fe6cbf2bf07c944b4dd8ee3c949d4daf 100644 --- a/activesupport/lib/active_support/backtrace_cleaner.rb +++ b/activesupport/lib/active_support/backtrace_cleaner.rb @@ -91,7 +91,7 @@ def add_gem_filter gems_paths = (Gem.path | [Gem.default_dir]).map { |p| Regexp.escape(p) } return if gems_paths.empty? - gems_regexp = %r{(#{gems_paths.join('|')})/(bundler/)?gems/([^/]+)-([\w.]+)/(.*)} + gems_regexp = %r{\A(#{gems_paths.join('|')})/(bundler/)?gems/([^/]+)-([\w.]+)/(.*)} gems_result = '\3 (\4) \5' add_filter { |line| line.sub(gems_regexp, gems_result) } end diff --git a/activesupport/test/clean_backtrace_test.rb b/activesupport/test/clean_backtrace_test.rb index a846312d68f2a4ebf6f9599d4ef174dcc9ba8ac4..dd62ef359b734bba6964ac77b376895b35350c61 100644 --- a/activesupport/test/clean_backtrace_test.rb +++ b/activesupport/test/clean_backtrace_test.rb @@ -124,4 +124,10 @@ def setup result = @bc.clean(backtrace) assert_equal %w[other/file.rb], result end + + test "should preserve lines that have a subpath matching a gem path" do + backtrace = [Gem.default_dir, *Gem.path].map { |path| "/parent#{path}/gems/nosuchgem-1.2.3/lib/foo.rb" } + + assert_equal backtrace, @bc.clean(backtrace) + end end