From 4739c5710f1d065e49fe71ae5601a88cea195c04 Mon Sep 17 00:00:00 2001 From: intrip Date: Thu, 19 Sep 2024 17:59:08 +0200 Subject: [PATCH] Fix infinite loop computing ERB dependencies with non-trailing interpolations Calling ```ruby ActionView::DependencyTracker::ERBTracker#add_static_dependency( [] "test/\#{bucket.bucketable_name.pluralize}/status/show" "\"") ``` Will loop indefinitely. Fixes it by parsing only template strings with a trailing template interpolation. --- .../action_view/dependency_tracker/erb_tracker.rb | 2 +- actionview/test/template/dependency_tracker_test.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/actionview/lib/action_view/dependency_tracker/erb_tracker.rb b/actionview/lib/action_view/dependency_tracker/erb_tracker.rb index 9bf87b1fa8286..3784c674629e7 100644 --- a/actionview/lib/action_view/dependency_tracker/erb_tracker.rb +++ b/actionview/lib/action_view/dependency_tracker/erb_tracker.rb @@ -116,7 +116,7 @@ def add_dynamic_dependency(dependencies, dependency) end def add_static_dependency(dependencies, dependency, quote_type) - if quote_type == '"' && dependency.include?('#{') + if quote_type == '"' && dependency.include?('#{') && dependency.end_with?("}") scanner = StringScanner.new(dependency) wildcard_dependency = +"" diff --git a/actionview/test/template/dependency_tracker_test.rb b/actionview/test/template/dependency_tracker_test.rb index ea988cf9049c8..d9a6b538e9cbf 100644 --- a/actionview/test/template/dependency_tracker_test.rb +++ b/actionview/test/template/dependency_tracker_test.rb @@ -243,6 +243,18 @@ class ERBTrackerTest < ActiveSupport::TestCase def make_tracker(name, template, view_paths = nil) ActionView::DependencyTracker::ERBTracker.new(name, template, view_paths) end + + def test_dependencies_with_interpolation_non_trailing + view_paths = ActionView::PathSet.new([File.expand_path("../fixtures/digestor", __dir__)]) + + template = FakeTemplate.new(%q{ + <%= render "#{type}/comments" %> + }, :erb) + + tracker = make_tracker("interpolation/_string", template, view_paths) + + assert_equal [ "\#{type}/comments" ], tracker.dependencies + end end module RubyTrackerTests