Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gem "appraisal"
gem "actionview", "~> 8.1"
gem "maxitest", "~> 7.0"
gem "minitest-difftastic"
gem "mocha", "~> 3.1.0"
gem "railties", "~> 8.1"
gem "rake", "~> 13.0"
gem "readline", "~> 0.0.4"
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ GEM
prism (~> 1.5)
minitest-difftastic (0.2.1)
difftastic (~> 0.6)
mocha (3.1.0)
ruby2_keywords (>= 0.0.5)
nokogiri (1.19.1-aarch64-linux-gnu)
racc (~> 1.4)
nokogiri (1.19.1-aarch64-linux-musl)
Expand Down Expand Up @@ -174,6 +176,7 @@ GEM
parser (>= 3.3.7.2)
prism (~> 1.7)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
securerandom (0.4.1)
stringio (3.2.0)
thor (1.5.0)
Expand Down Expand Up @@ -203,6 +206,7 @@ DEPENDENCIES
appraisal
maxitest (~> 7.0)
minitest-difftastic
mocha (~> 3.1.0)
railties (~> 8.1)
rake (~> 13.0)
reactionview!
Expand Down
3 changes: 2 additions & 1 deletion gemfiles/rails_7_0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

source "https://rubygems.org"

gem "actionview", "~> 7.0.0"
gem "appraisal"
gem "actionview", "~> 7.0.0"
gem "maxitest", "~> 7.0"
gem "minitest-difftastic"
gem "mocha", "~> 3.1.0"
gem "railties", "~> 7.0.0"
gem "rake", "~> 13.0"
gem "readline", "~> 0.0.4"
Expand Down
4 changes: 4 additions & 0 deletions gemfiles/rails_7_0.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ GEM
prism (~> 1.5)
minitest-difftastic (0.2.1)
difftastic (~> 0.6)
mocha (3.1.0)
ruby2_keywords (>= 0.0.5)
mutex_m (0.3.0)
nokogiri (1.19.1-aarch64-linux-gnu)
racc (~> 1.4)
Expand Down Expand Up @@ -149,6 +151,7 @@ GEM
parser (>= 3.3.7.2)
prism (~> 1.7)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
securerandom (0.4.1)
thor (1.5.0)
tsort (0.2.0)
Expand All @@ -175,6 +178,7 @@ DEPENDENCIES
appraisal
maxitest (~> 7.0)
minitest-difftastic
mocha (~> 3.1.0)
railties (~> 7.0.0)
rake (~> 13.0)
reactionview!
Expand Down
3 changes: 2 additions & 1 deletion gemfiles/rails_7_1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

source "https://rubygems.org"

gem "actionview", "~> 7.1.0"
gem "appraisal"
gem "actionview", "~> 7.1.0"
gem "maxitest", "~> 7.0"
gem "minitest-difftastic"
gem "mocha", "~> 3.1.0"
gem "railties", "~> 7.1.0"
gem "rake", "~> 13.0"
gem "readline", "~> 0.0.4"
Expand Down
4 changes: 4 additions & 0 deletions gemfiles/rails_7_1.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ GEM
prism (~> 1.5)
minitest-difftastic (0.2.1)
difftastic (~> 0.6)
mocha (3.1.0)
ruby2_keywords (>= 0.0.5)
mutex_m (0.3.0)
nokogiri (1.19.1-aarch64-linux-gnu)
racc (~> 1.4)
Expand Down Expand Up @@ -180,6 +182,7 @@ GEM
parser (>= 3.3.7.2)
prism (~> 1.7)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
securerandom (0.4.1)
stringio (3.2.0)
thor (1.5.0)
Expand Down Expand Up @@ -207,6 +210,7 @@ DEPENDENCIES
appraisal
maxitest (~> 7.0)
minitest-difftastic
mocha (~> 3.1.0)
railties (~> 7.1.0)
rake (~> 13.0)
reactionview!
Expand Down
3 changes: 2 additions & 1 deletion gemfiles/rails_7_2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

source "https://rubygems.org"

gem "actionview", "~> 7.2.0"
gem "appraisal"
gem "actionview", "~> 7.2.0"
gem "maxitest", "~> 7.0"
gem "minitest-difftastic"
gem "mocha", "~> 3.1.0"
gem "railties", "~> 7.2.0"
gem "rake", "~> 13.0"
gem "readline", "~> 0.0.4"
Expand Down
4 changes: 4 additions & 0 deletions gemfiles/rails_7_2.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ GEM
prism (~> 1.5)
minitest-difftastic (0.2.1)
difftastic (~> 0.6)
mocha (3.1.0)
ruby2_keywords (>= 0.0.5)
nokogiri (1.19.1-aarch64-linux-gnu)
racc (~> 1.4)
nokogiri (1.19.1-aarch64-linux-musl)
Expand Down Expand Up @@ -179,6 +181,7 @@ GEM
parser (>= 3.3.7.2)
prism (~> 1.7)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
securerandom (0.4.1)
stringio (3.2.0)
thor (1.5.0)
Expand Down Expand Up @@ -207,6 +210,7 @@ DEPENDENCIES
appraisal
maxitest (~> 7.0)
minitest-difftastic
mocha (~> 3.1.0)
railties (~> 7.2.0)
rake (~> 13.0)
reactionview!
Expand Down
3 changes: 2 additions & 1 deletion gemfiles/rails_8_0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

source "https://rubygems.org"

gem "actionview", "~> 8.0.0"
gem "appraisal"
gem "actionview", "~> 8.0.0"
gem "maxitest", "~> 7.0"
gem "minitest-difftastic"
gem "mocha", "~> 3.1.0"
gem "railties", "~> 8.0.0"
gem "rake", "~> 13.0"
gem "readline", "~> 0.0.4"
Expand Down
4 changes: 4 additions & 0 deletions gemfiles/rails_8_0.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ GEM
prism (~> 1.5)
minitest-difftastic (0.2.1)
difftastic (~> 0.6)
mocha (3.1.0)
ruby2_keywords (>= 0.0.5)
nokogiri (1.19.1-aarch64-linux-gnu)
racc (~> 1.4)
nokogiri (1.19.1-aarch64-linux-musl)
Expand Down Expand Up @@ -175,6 +177,7 @@ GEM
parser (>= 3.3.7.2)
prism (~> 1.7)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
securerandom (0.4.1)
stringio (3.2.0)
thor (1.5.0)
Expand Down Expand Up @@ -204,6 +207,7 @@ DEPENDENCIES
appraisal
maxitest (~> 7.0)
minitest-difftastic
mocha (~> 3.1.0)
railties (~> 8.0.0)
rake (~> 13.0)
reactionview!
Expand Down
3 changes: 2 additions & 1 deletion gemfiles/rails_8_1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

source "https://rubygems.org"

gem "actionview", "~> 8.1.0"
gem "appraisal"
gem "actionview", "~> 8.1.0"
gem "maxitest", "~> 7.0"
gem "minitest-difftastic"
gem "mocha", "~> 3.1.0"
gem "railties", "~> 8.1.0"
gem "rake", "~> 13.0"
gem "readline", "~> 0.0.4"
Expand Down
4 changes: 4 additions & 0 deletions gemfiles/rails_8_1.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ GEM
prism (~> 1.5)
minitest-difftastic (0.2.1)
difftastic (~> 0.6)
mocha (3.1.0)
ruby2_keywords (>= 0.0.5)
nokogiri (1.19.1-aarch64-linux-gnu)
racc (~> 1.4)
nokogiri (1.19.1-aarch64-linux-musl)
Expand Down Expand Up @@ -174,6 +176,7 @@ GEM
parser (>= 3.3.7.2)
prism (~> 1.7)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
securerandom (0.4.1)
stringio (3.2.0)
thor (1.5.0)
Expand Down Expand Up @@ -203,6 +206,7 @@ DEPENDENCIES
appraisal
maxitest (~> 7.0)
minitest-difftastic
mocha (~> 3.1.0)
railties (~> 8.1.0)
rake (~> 13.0)
reactionview!
Expand Down
3 changes: 2 additions & 1 deletion gemfiles/rails_8_2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

source "https://rubygems.org"

gem "actionview", github: "rails/rails"
gem "appraisal"
gem "actionview", github: "rails/rails"
gem "maxitest", "~> 7.0"
gem "minitest-difftastic"
gem "mocha", "~> 3.1.0"
gem "railties", github: "rails/rails"
gem "rake", "~> 13.0"
gem "readline", "~> 0.0.4"
Expand Down
4 changes: 4 additions & 0 deletions gemfiles/rails_8_2.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ GEM
prism (~> 1.5)
minitest-difftastic (0.2.1)
difftastic (~> 0.6)
mocha (3.1.0)
ruby2_keywords (>= 0.0.5)
nokogiri (1.19.1-aarch64-linux-gnu)
racc (~> 1.4)
nokogiri (1.19.1-aarch64-linux-musl)
Expand Down Expand Up @@ -180,6 +182,7 @@ GEM
parser (>= 3.3.7.2)
prism (~> 1.7)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
securerandom (0.4.1)
stringio (3.2.0)
thor (1.5.0)
Expand Down Expand Up @@ -209,6 +212,7 @@ DEPENDENCIES
appraisal
maxitest (~> 7.0)
minitest-difftastic
mocha (~> 3.1.0)
railties!
rake (~> 13.0)
reactionview!
Expand Down
14 changes: 13 additions & 1 deletion lib/reactionview/template/handlers/erb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,24 @@ class ERB < ActionView::Template::Handlers::ERB
autoload :Herb, "reactionview/template/handlers/herb/herb"

def call(template, source)
if template.format == :html && ReActionView.config.intercept_erb
if intercept_template?(template)
::ReActionView::Template::Handlers::Herb.call(template, source)
else
super
end
end

private

def intercept_template?(template)
template.format == :html && ReActionView.config.intercept_erb && local_template?(template)
end

def local_template?(template)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Short of exposing this as a class method on the Herb handler, it felt like this duplication was either warranted, so we should consider a TemplateUtilities module that we can mix in. Thoughts?

return true unless template.respond_to?(:identifier) && template.identifier

template.identifier.start_with?(Rails.root.to_s)
end
end
end
end
Expand Down
21 changes: 21 additions & 0 deletions test/template/handlers/herb_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -365,4 +365,25 @@ def @view_context.ui_badge(count, **_options)

assert_compiled_snapshot(template)
end

test "does not process templates that are not local" do
ReActionView.config.intercept_erb = true
Rails.stubs(:root).returns("/local/template")

template = %(<p><h2>I am invalid</h2></p>)
template_obj = ActionView::Template.new(
template,
"test_template",
ReActionView::Template::Handlers::ERB,
virtual_path: "test",
format: :html,
locals: []
)

compiled_source = template_obj.handler.call(template_obj, template)
result = @view_context.instance_eval(compiled_source).to_s

normalized_result = result.gsub(/>\s+</, "><").gsub(/\s+/, " ").strip
assert_equal "<p><h2>I am invalid</h2></p>", normalized_result
Comment on lines +383 to +387
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test pattern follows your others, but, much to my surprise, something in this setup doesn't raise an error when I encounter an erroneous template. This frustrated my abilities to implement logging.

We know real world usage raises per the original issue. Is there something askew with the test setup?

end
end
1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

require "maxitest/autorun"
require "minitest/spec"
require "mocha/minitest"

require_relative "snapshot_utils"

Expand Down
Loading