Skip to content

Fix JSON::GeneratorError for objects with invalid UTF-8 in to_s - #1199

Merged
waltjones merged 1 commit into
rollbar:masterfrom
grk:fix-encoding-invalid-to_s-objects
Jan 8, 2026
Merged

Fix JSON::GeneratorError for objects with invalid UTF-8 in to_s#1199
waltjones merged 1 commit into
rollbar:masterfrom
grk:fix-encoding-invalid-to_s-objects

Conversation

@grk

@grk grk commented Jan 8, 2026

Copy link
Copy Markdown
Contributor

Description of the change

Rollbar::Encoding.encode only processed String and Symbol types. When objects with to_s methods returning invalid UTF-8 were included in the payload, they bypassed encoding and caused JSON serialization to fail with "source sequence is illegal/malformed utf-8".

Now all non-JSON-native types are passed through the Encoder, which already calls to_s and handles encoding normalization.

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Maintenance
  • New release

Related issues

Checklists

Development

  • Lint rules pass locally
  • The code changed/added as part of this pull request has been covered with tests
  • All tests related to the changed code pass in development

Code review

  • This pull request has a descriptive title and information useful to a reviewer. There may be a screenshot or screencast attached
  • "Ready for review" label attached to the PR and reviewers assigned
  • Issue from task tracker has a link to this pull request
  • Changes have been reviewed by at least one other engineer

Rollbar::Encoding.encode only processed String and Symbol types.
When objects with to_s methods returning invalid UTF-8 were included
in the payload, they bypassed encoding and caused JSON serialization
to fail with "source sequence is illegal/malformed utf-8".

Now all non-JSON-native types are passed through the Encoder, which
already calls to_s and handles encoding normalization.

Fixes rollbar#1196

@waltjones waltjones left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good , and thank you!

@waltjones
waltjones merged commit fb20a58 into rollbar:master Jan 8, 2026
31 checks passed
@waltjones

Copy link
Copy Markdown
Contributor

Released in v3.8.0.

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

Successfully merging this pull request may close these issues.

Internal failsafe when serializing invalid utf8 content

2 participants