gazay / gon

Your Rails variables in your JS
MIT License
3.05k stars 184 forks source link

Parse error when jbuilder partials do not end with a new line #223

Open RavenXce opened 7 years ago

RavenXce commented 7 years ago

Steps to reproduce:

  1. Create a partial jbuilder does not end in a new line, and has a do..end block:
# _partial.json.builder
json.bar do
  json.buzz '42'
end # no new line after this
  1. Create a main jbuilder file which includes the partial:
# new.json.builder
json.foo do
  json.partial! 'foo/partial', locals: {}
end
  1. Render the jbuilder template:
# in foo controller:
def new
  gom.jbuilder
end

Expected result:

json variable gon.foo.bar.buzz = 42 is assigned.

Actual result:

Exception thrown: SyntaxError - syntax error, unexpected end-of-input, expecting keyword_end Stacktrace:

gon (6.1.0) lib/gon/jbuilder/parser.rb:70:in `block in parse_source'
jbuilder (2.6.3) lib/jbuilder.rb:18:in `initialize'
jbuilder (2.6.3) lib/jbuilder/jbuilder_template.rb:15:in `initialize'
jbuilder (2.6.3) lib/jbuilder.rb:23:in `encode'
gon (6.1.0) lib/gon/jbuilder/parser.rb:69:in `parse_source'
gon (6.1.0) lib/gon/jbuilder/parser.rb:25:in `parse!'
gon (6.1.0) lib/gon/jbuilder.rb:18:in `handler'
gon (6.1.0) lib/gon.rb:96:in `jbuilder'
...

Notes:

Adding a new line at the end of the partial stops the error from happening.