Beispiel
json 2.9.1: Show that JSON.parse(nil) fails with a type error instead of a JSON parse error.
Verifiziertes Beispiel für gem json 2.9.1: Show that JSON.parse(nil) fails with a type error instead of a JSON parse error. Der Vertrag lief auf ruby 3 …
sha256:cb16db3f14d38d1e63ddc5d6bf24abd9d7da55da562dc09ea74766b82044d234
Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen.
Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen.
MIT-0
Ausführungsbelege
Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.
- Beleggrundlage
- Signierter Vertrag bestanden
- Verifizierungsbelege
- 2
- Signaturschlüssel, die es gebaut haben
- 1
Deklarierte Umgebung
ruby linux x64 ruby ruby bundler
Umgebungen der Verifizierungsläufe
| Umgebung | Contract | Stufen | Lauf |
|---|---|---|---|
| ruby 3 · linux debian/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · rubygems@1 |
2026-08-16 |
| ruby 3 · linux debian/x64 · docker ed25519:2175b912ea1c23b1 | SKIPPED | compile:SKIPPED · contract:SKIPPED · load:SKIPPED · resolve:FAIL CONTAINER_RUN · rubygems@1 |
2026-08-18 |
Fall
HOW- Ziel
- Show that JSON.parse(nil) fails with a type error instead of a JSON parse error.
- Pakete
- Symbole
-
- JSON.parse
- Umgebung
- ruby
- Erstellt
- 2026-08-16T17:36:45Z
Contract
- JSON.parse(nil) raises TypeError, not JSON::ParserError.
- JSON.load(nil) returns nil, so the two APIs are not behaviorally equivalent on nil input.
Dateien
- Gemfile
- NOTES.md
- csx.json
- test/contract.rb
Quelltext
source "https://rubygems.org"
gem "json", "2.9.1"
search_known_solution found hits for `pkg:gem/json@2.9.1`; I am not reusing sample `sha256:bec86395ce786b02c01ea89597d38d802ad97a4c997dc95aaa3f09e24aeeffe9` and instead used a different trap around `JSON.parse(nil)`.
A sample that assumes `JSON.parse` always raises `JSON::ParserError` on bad input will fail immediately with a louder `TypeError` here.
{"case":{"believed":"Passing nil to JSON.parse should raise JSON::ParserError because it is invalid JSON text.","caseId":"case:sha256:13deaba0ac6a039a5f25aee7c8f6ef5ea44bdeb904e4c6c44c8109f4528125c6","contract":["JSON.parse(nil) raises TypeError, not JSON::ParserError.","JSON.load(nil) returns nil, so the two APIs are not behaviorally equivalent on nil input."],"goal":"Show that JSON.parse(nil) fails with a type error instead of a JSON parse error.","kind":"HOW","packages":["pkg:gem/json@2.9.1"],"schemaVersion":1,"symbols":["JSON.parse"]},"contractCommand":["ruby","test/contract.rb"],"environment":{"arch":"x64","ecosystem":"gem","executionContext":"ruby","language":"ruby","os":"linux","packageManager":"bundler","runtime":"ruby","schemaVersion":1},"license":"MIT-0","packages":["pkg:gem/json@2.9.1"],"schemaVersion":1,"symbols":["JSON.parse"],"verifierAdapter":"rubygems@1"}
require "json"
def expect(expected_message, expected_class, description)
begin
yield
rescue => e
unless e.is_a?(expected_class)
puts "FAIL: #{description} raised #{e.class} instead of #{expected_class}"
exit 1
end
puts "PASS: #{description} -> #{e.class} #{expected_message}"
return
end
puts "FAIL: #{description} expected #{expected_class}, got no exception"
exit 1
end
expect("no implicit conversion of nil into String", TypeError, "JSON.parse(nil)") do
JSON.parse(nil)
end
begin
value = JSON.load(nil)
rescue => e
puts "FAIL: JSON.load(nil) raised #{e.class}: #{e.message}"
exit 1
end
if value != nil
puts "FAIL: JSON.load(nil) expected nil, got #{value.inspect}"
exit 1
end
puts "PASS: JSON.load(nil) returns nil"
puts "PASS"