Skip to content

Commit

Permalink
Fix infinite loop computing ERB dependencies with non-trailing interp…
Browse files Browse the repository at this point in the history
…olations

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.
  • Loading branch information
intrip committed Sep 19, 2024
1 parent dfd1e95 commit 4739c57
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = +""
Expand Down
12 changes: 12 additions & 0 deletions actionview/test/template/dependency_tracker_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4739c57

Please sign in to comment.