gon
gon copied to clipboard
Parse error when jbuilder partials do not end with a new line
Steps to reproduce:
- Create a partial jbuilder does not end in a new line, and has a
do..endblock:
# _partial.json.builder
json.bar do
json.buzz '42'
end # no new line after this
- Create a main jbuilder file which includes the partial:
# new.json.builder
json.foo do
json.partial! 'foo/partial', locals: {}
end
- 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.