Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force close final statement in templates #578

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions lib/jbuilder/jbuilder_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def _render_partial_with_options(options)
results = CollectionRenderer
.new(@context.lookup_context, options) { |&block| _scope(&block) }
.render_collection_with_partial(collection, partial, @context, nil)

array! if results.respond_to?(:body) && results.body.nil?
else
array!
Expand Down Expand Up @@ -284,7 +284,7 @@ class JbuilderHandler
def self.call(template, source = nil)
source ||= template.source
# this juggling is required to keep line numbers right in the error
%{__already_defined = defined?(json); json||=JbuilderTemplate.new(self); #{source}
%{__already_defined = defined?(json); json||=JbuilderTemplate.new(self); #{source};
json.target! unless (__already_defined && __already_defined != "method")}
end
end
11 changes: 11 additions & 0 deletions test/jbuilder_template_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ class JbuilderTemplateTest < ActiveSupport::TestCase
assert_equal "hello", result["content"]
end

test "partial by name with hash value omission (punning) as last statement [3.1+]" do
major, minor, _ = RUBY_VERSION.split(".").map(&:to_i)
return unless (major == 3 && minor >= 1) || major > 3

result = render(<<-JBUILDER)
content = "hello"
json.partial! "partial", content:
JBUILDER
assert_equal "hello", result["content"]
end

test "partial by options containing nested locals" do
result = render('json.partial! partial: "partial", locals: { content: "hello" }')
assert_equal "hello", result["content"]
Expand Down
Loading