Fix: Invalid JSON on gc-stats (#1801)#4
Conversation
* Fix: Invalid JSON on gc-stats Credits of this patch should be for @jdsundberg, who reported the issue but never sent a patch. Link to his bug report is below. Closes puma#1687. * Update tests so JSON response is correctly parsed JSON without a whitespace between key and values wasn't being correctly parsed (for example: `key: 'value'` was processed ok, but `key:'value'` wasn't).
Greptile OverviewGreptile SummaryFixed invalid JSON generation in the Key Changes:
Issue Fixed: Minor Issue: Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant Status as Puma::App::Status
participant GC as Ruby GC
participant JSON as JSON Library
Client->>Status: GET /gc-stats
Status->>GC: GC.stat
GC-->>Status: Hash of GC statistics
Status->>JSON: .to_json
JSON-->>Status: Valid JSON string
Status-->>Client: 200 OK with JSON response
Note over Status,JSON: Old implementation manually<br/>constructed JSON strings,<br/>causing invalid JSON for<br/>non-numeric values
Note over Status,JSON: New implementation uses<br/>to_json for proper<br/>escaping and formatting
|
Additional Comments (1)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! Prompt To Fix With AIThis is a comment left during a code review.
Path: test/test_cli.rb
Line: 179:185
Comment:
Inconsistent JSON parsing - this first gc-stats check still uses manual regex parsing while the second check (line 199) uses `JSON.parse`. Both should use `JSON.parse` for consistency.
```suggestion
gc_stats = JSON.parse(json_line)
gc_count_before = gc_stats["count"].to_i
```
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise. |
PR_054