Build headers_json with JSON.generate so json 3 can't fail every request - #28
Merged
Merged
Conversation
With json 3 and ActiveSupport 8.0 or older, a direct #to_json call goes through ActiveSupport's encoder, which passes quirks_mode: to JSON.generate and json 3 rejects it. HTTPRequest and HTTPResponse build headers_json with #to_json, so every request raises there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ActiveSupport older than 7.2.4 and every 8.0 release routes a direct #to_json call through its own encoder, which passes quirks_mode: to JSON.generate. json 3 rejects that keyword, so with both installed every request raised in HTTPEvents. JSON.generate encodes the headers Hash natively. With ActiveSupport loaded, <, > and & are no longer escaped as <, > and &; the JSON means the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With json 3 installed next to an ActiveSupport that still passes
quirks_mode:toJSON.generate(older than 7.2.4, and every 8.0 release), any direct#to_jsoncall goes through ActiveSupport's encoder and raises, because json 3 rejects that keyword.HTTPRequestandHTTPResponsebuildheaders_jsonwith#to_json, soHTTPEventsraises on every request. From the red-team of 0.2.8: with json ≥ 3 on Rails ≤ 8.0 every request returned a 500 and nothing was logged, while a stock app without the gem still served its pages.HTTPRequestandHTTPResponsebuildheaders_jsonwith::JSON.generate. These were the onlyto_jsoncalls inlib.Hash#to_jsonthe way ActiveSupport ≤ 8.0 behaves under json 3: a direct call raises, while a call from insideJSON.generate(which passes aJSON::State) goes through to json.Behaviour and compatibility:
headers_jsonno longer escapes<,>and&as<,>and&(ActiveSupport'sescape_html_entities_in_json). The JSON means the same after parsing.Targets the logtail-rack 0.2.9 patch release. No dependencies on the other open PRs. The core gem's own
to_jsoncalls (STDOUT logging, error backtraces) are changed separately in logtail-ruby.The first commit only adds the tests and is expected to fail on CI; the fix follows in the next commit.
🤖 Generated with Claude Code