gon
gon copied to clipboard
Parse error when using jbuilder partials without an options hash
Steps to reproduce:
- Call a partial with no options hash:
# new.json.jbuilder
json.foo do
json.partial! 'foo/partial'
end
- Render the jbuilder template
# foo controller
def new
gon.jbuilder
end
Expected result:
The template is assigned to the JS gon.foo variable successfully.
Actual result:
Exception thrown: NoMethodError: undefined method '[]' for nil:NilClass
Stacktrace:
21:29:06 web.1 | gon (6.1.0) lib/gon/jbuilder/parser.rb:78:in `parse_partial'
21:29:06 web.1 | gon (6.1.0) lib/gon/jbuilder/parser.rb:119:in `block in find_partials'
21:29:06 web.1 | gon (6.1.0) lib/gon/jbuilder/parser.rb:117:in `find_partials'
21:29:06 web.1 | gon (6.1.0) lib/gon/jbuilder/parser.rb:22:in `parse!'
21:29:06 web.1 | gon (6.1.0) lib/gon/jbuilder.rb:18:in `handler'
21:29:06 web.1 | gon (6.1.0) lib/gon.rb:96:in `jbuilder'
...
Notes:
It seems that line 78 of the parser tries to access the MatchData array even though String#match will return nil when there are no matches. The options_hash will therefore never be empty in a valid jbuilder template, meaning that the check is wrongly done.