Skip to content

Instantly share code, notes, and snippets.

@shivabhusal
Created November 28, 2025 09:33
Show Gist options
  • Select an option

  • Save shivabhusal/204daaa9282caef1697aea3065565620 to your computer and use it in GitHub Desktop.

Select an option

Save shivabhusal/204daaa9282caef1697aea3065565620 to your computer and use it in GitHub Desktop.
ERB partial locals parsing fails when locals comment spans multiple lines https://github.com/rails/rails/issues/56239
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
gem 'pry'
gem "rails", '~> 7.2.2.2'
# If you want to test against edge Rails replace the previous line with this:
# gem "rails", github: "rails/rails", branch: "main"
end
require "action_controller/railtie"
require "action_view/railtie"
require "minitest/autorun"
class TestApp < Rails::Application
config.load_defaults Rails::VERSION::STRING.to_f
config.eager_load = false
config.logger = Logger.new($stdout)
config.secret_key_base = "secret_key_base"
end
Rails.application.initialize!
class BugTest < ActionView::TestCase
helper do
def upcase(value)
value.upcase
end
end
def test_inner_partial_inline_locals
tmp_dir = Dir.mktmpdir
@tmp_path = Pathname(tmp_dir)
File.write(@tmp_path.join("_partial.html.erb"), <<~HTML)
<p><%= arg_1 %></p>
<p><%= arg_2 %></p>
<p><%= arg_3 %></p>
HTML
File.write(@tmp_path.join("main.html.erb"), <<~ERB)
<div>
<h1>Title</h1>
<%= render partial: "partial", locals: { arg_1: "value1", arg_2: "value2", arg_3: "value3" } %>
</div>
ERB
# config ActionController to search for templates at our tmp dir
ActionController::Base.prepend_view_path @tmp_path
render template: 'main'
element_contents = rendered.html.css("p").map(&:text)
assert_equal element_contents, ["value1", "value2", "value3"]
FileUtils.rm_rf tmp_dir
end
def test_inner_partial_multiline_locals
tmp_dir = Dir.mktmpdir
@tmp_path = Pathname(tmp_dir)
File.write(@tmp_path.join("_partial.html.erb"), <<~HTML)
<p><%= arg_1 %></p>
<p><%= arg_2 %></p>
<p><%= arg_3 %></p>
HTML
File.write(@tmp_path.join("main.html.erb"), <<~ERB)
<div>
<h1>Title</h1>
<%= render partial: "partial", locals: { arg_1: "value1",
arg_2: "value2",
arg_3: "value3" } %>
</div>
ERB
# config ActionController to search for templates at our tmp dir
ActionController::Base.prepend_view_path @tmp_path
render template: 'main'
element_contents = rendered.html.css("p").map(&:text)
assert_equal element_contents, ["value1", "value2", "value3"]
FileUtils.rm_rf tmp_dir
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment