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

Parse error when using jbuilder partials without an options hash #224

Open
RavenXce opened this issue Apr 25, 2017 · 0 comments
Open

Parse error when using jbuilder partials without an options hash #224

RavenXce opened this issue Apr 25, 2017 · 0 comments

Comments

@RavenXce
Copy link

RavenXce commented Apr 25, 2017

Steps to reproduce:

  1. Call a partial with no options hash:
# new.json.jbuilder
json.foo do
  json.partial! 'foo/partial'
end
  1. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant