Skip to content

Rollbar.js integration issue: JS functions are emitted as quoted strings with json gem ≥ 2.17 #1205

Description

@jordan-brough

Summary

When you configure a JavaScript function for the Rollbar.js snippet (for example checkIgnore or transform), rollbar-gem is supposed to print it into the page as raw JavaScript:

checkIgnore: function(){ ... }

But with the json gem version 2.17.0 or newer, rollbar-gem prints it as a quoted string instead:

checkIgnore: "function(){ ... }"

That's not a function anymore — it's just text. The browser then can't use it, and the Rollbar.js config is broken on the page.

json 2.17.0 was released Dec 2025.

Why this happens

To support raw JavaScript, rollbar-gem wraps the value in Rollbar::JSON::Value and serializes it with a special state object, Rollbar::JSON::JsOptionsState (which is a subclass of JSON::State):

Rollbar::JSON::Value#to_json decides "raw JS vs. quoted string" by checking whether the state object it receives is exactly that class:

def to_json(opts = {})
  return value if opts.class == Rollbar::JSON::JsOptionsState  # <-- exact class check
  %Q["#{value}"]
end

In json ≤ 2.16, the object passed to to_json was exactly a Rollbar::JSON::JsOptionsState, so the check passed.

In json ≥ 2.17, the generator no longer passes that exact subclass through, so opts.class == Rollbar::JSON::JsOptionsState is now false — and rollbar-gem falls through to the quoted-string branch.

Repro

Save this as repro.rb and run ruby repro.rb.
Change which version of json is enabled to see success/failure.

require "bundler/inline"


gemfile do
  source "https://rubygems.org"

  gem "rollbar", "3.8.0"
  gem "logger"

  # working:
  gem "json", "2.16.0"

  # broken:
  # gem "json", "2.19.4"
end

require "rollbar/middleware/js/json_value"

raw_js = Rollbar::JSON::Value.new("function(){ return true }")
output  = JSON.generate({ checkIgnore: raw_js }, Rollbar::JSON::JsOptionsState.new)

puts "json #{JSON::VERSION} => #{output}"

Result with json 2.19.4 (broken):

json 2.19.4 => {"checkIgnore":"function(){ return true }"}

Result with json 2.16.0 (correct):

json 2.16.0 => {"checkIgnore":function(){ return true }}

Notice the quotes around the function in the broken case.

Impact

Any app that passes a JavaScript function to the Rollbar.js options (e.g. checkIgnore) gets a broken Rollbar.js config in the browser as soon as json is upgraded to ≥ 2.17. Because nothing raises an error, it can break silently — Rollbar.js just stops behaving as configured. Today the only workaround is to pin the json gem below 2.17.

Environment

  • rollbar gem: 3.8.0
  • Broken on json ≥ 2.17 (confirmed on 2.19.4); works on json ≤ 2.16 (confirmed on 2.16.0 and 2.15.2.x)
  • Ruby: 4.0.2

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions