Skip to content

Forbid JSON::ResumableParser#<< while the parser is in use#1018

Merged
byroot merged 1 commit into
ruby:masterfrom
mame:forbid-feed-during-callback
Jun 18, 2026
Merged

Forbid JSON::ResumableParser#<< while the parser is in use#1018
byroot merged 1 commit into
ruby:masterfrom
mame:forbid-feed-during-callback

Conversation

@mame

@mame mame commented Jun 18, 2026

Copy link
Copy Markdown
Member

Currently #<< is allowed even while in_use == true.

require "json"
parser = nil
parser = JSON::ResumableParser.new(on_load: ->(o) { parser << "2]" if o == 1; o })
parser << "[1,"
parser.parse   # => true
parser.value   # => [1, 2]   (the callback fed "2]" from inside the running parse)

Given that #clear is forbidden while in_use == true, this is probably not intentional? It may be harmless, but I think it is safer to forbid this code unless there is a clear use case.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@byroot byroot force-pushed the forbid-feed-during-callback branch from 77e574f to e369212 Compare June 18, 2026 17:11
@byroot byroot merged commit 489b8c1 into ruby:master Jun 18, 2026
42 checks passed
@mame mame deleted the forbid-feed-during-callback branch June 18, 2026 17:25
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.

2 participants