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

JSON::GeneratorError after moving from 1.4.0 to 2.0.x #29

Open
lunks opened this issue Oct 7, 2015 · 4 comments
Open

JSON::GeneratorError after moving from 1.4.0 to 2.0.x #29

lunks opened this issue Oct 7, 2015 · 4 comments

Comments

@lunks
Copy link
Contributor

lunks commented Oct 7, 2015

I'm just moving a previous issue from the old repo here. Is there a way of doing this using ExecJS > 1.4.0?

Using this in a js.coffee erb template

$("#stats").replaceWith("<%= escape_javascript(render @template) %>")
now causes this error

JSON::GeneratorError - only generation of JSON objects or arrays allowed:
  /Users/Nick/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/json/common.rb:216:in `generate'
  /Users/Nick/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/json/common.rb:345:in `dump'
  execjs (2.0.0) lib/execjs/external_runtime.rb:19:in `eval'
  execjs (2.0.0) lib/execjs/external_runtime.rb:33:in `call'
  coffee-script (2.2.0) lib/coffee_script.rb:57:in `compile'
  app/views/admin/stats/stats.js.coffee:1:in `_app_views_admin_stats_stats_js_coffee___1014294459951170846_70216695895960'
This worked just fine with 1.4.0 Should a different approach now be used?
@rafaelfranca
Copy link
Member

Is not it missing the erb extension?

@chancancode
Copy link
Member

Actually. I know the problem, one of the JSON.generate call is missing quirks_mode: true. (By default it only allows you to make {...} and [...], this flag allows bare strings, numbers, booleans and nulls as well.

We just have to verify it wasn't intentional and add the flag.

@chancancode
Copy link
Member

Specifically:

eval "#{identifier}.apply(this, #{::JSON.generate(args)})"

The only thing that is giving me minor doubts is that the original commit that introduced it did it in one place but not the other, but I'm pretty sure it was just a mistake.

@lunks
Copy link
Contributor Author

lunks commented Oct 7, 2015

It has the erb extension. It seems the issue was lingering in the old repo and no one noticed it.

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

3 participants