mcp: check that UnmarshalJSON methods for Content don't panic on nil
Introduces a new test file content_nil_test.go which verifies that UnmarshalJSON methods for various Content types do not panic when unmarshaling onto nil pointers. Adds a nil check in contentFromWire function to guard against a nil wire.Content parameter. Tests cover different scenarios, including valid and invalid content types, as well as cases with empty or missing content fields. For #205
This commit is contained in:
parent
16f2857700
commit
cfa5c1d802
1 changed files with 227 additions and 0 deletions
|
|
@ -252,6 +252,9 @@ func contentsFromWire(wires []*wireContent, allow map[string]bool) ([]Content, e
|
|||
}
|
||||
|
||||
func contentFromWire(wire *wireContent, allow map[string]bool) (Content, error) {
|
||||
if wire == nil {
|
||||
return nil, fmt.Errorf("content wire is nil")
|
||||
}
|
||||
if allow != nil && !allow[wire.Type] {
|
||||
return nil, fmt.Errorf("invalid content type %q", wire.Type)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue