Skip to content

Commit 6ccc102

Browse files
committed
Fix allow_blank parsing option to only consider strings.
Ref: #946
1 parent 3f32c47 commit 6ccc102

File tree

3 files changed

+4
-1
lines changed

3 files changed

+4
-1
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### Unreleased
44

5+
* Fix `allow_blank` parsing option to no longer allow invalid types (e.g. `load([], allow_blank: true)` now raise a type error).
56
* Add `allow_invalid_escape` parsing option to ignore backslashes that aren't followed by one of the valid escape characters.
67

78
### 2026-02-03 (2.18.1)

lib/json/common.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ def load(source, proc = nil, options = nil)
880880
end
881881
end
882882

883-
if opts[:allow_blank] && (source.nil? || source.empty?)
883+
if opts[:allow_blank] && (source.nil? || (String === source && source.empty?))
884884
source = 'null'
885885
end
886886

test/json/json_common_interface_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ def test_load_null
150150
assert_equal nil, JSON.load(nil, nil, :allow_blank => true)
151151
assert_raise(TypeError) { JSON.load(nil, nil, :allow_blank => false) }
152152
assert_raise(JSON::ParserError) { JSON.load('', nil, :allow_blank => false) }
153+
assert_raise(TypeError) { JSON.load([], nil, :allow_blank => true) }
154+
assert_raise(TypeError) { JSON.load({}, nil, :allow_blank => true) }
153155
end
154156

155157
def test_unsafe_load

0 commit comments

Comments
 (0)