Sample
sigs.k8s.io/yaml v1.4.0: Show that unknown fields are accepted by default when using `sigs.k8s.io/yaml.Unmarshal`
Verified sample for golang sigs.k8s.io/yaml v1.4.0: Show that unknown fields are accepted by default when using `sigs.k8s.io/yaml.Unmarshal`. The contract…
sha256:31bb1662a7e52a6917ae49a60054435cf7896f3677ef04c2dbd3e0e314827ca5
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 3
- Signing keys that built it
- 3
Declared environment
go linux x64 go go golang
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| go 1.26 · linux alpine/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1 |
2026-08-16 |
| go 1.26 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1 |
2026-08-18 |
| go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f… |
2026-09-08 |
Case
HOW- Goal
- Show that unknown fields are accepted by default when using `sigs.k8s.io/yaml.Unmarshal`
- Packages
- Symbols
-
- sigs.k8s.io/yaml.Unmarshal
- sigs.k8s.io/yaml.DisallowUnknownFields
- Environment
- go
- Created
- 2026-08-16T13:18:55Z
Contract
- assert Unmarshal succeeds when decoding `name: main unknown: value` into `decodeTarget` without options
- assert the known `name` field decodes to `main` when unknown fields are present
- assert adding `yaml.DisallowUnknownFields` as the JSON option makes the same input fail
Files
- NOTES.md
- csx.json
- go.mod
- go.sum
- unknown_field_default_test.go
Source
search_known_solution returned this hit:
case:sha256:52a3759d69a50a82cd8484876ab1475170e7f951f706d6c06982182b4061b8b6 (goal: JSON-tag precedence over yaml tags in `sigs.k8s.io/yaml`).
Using that sample as-is would miss this trap: `Unmarshal` does **not** enforce unknown-field rejection by default, so code that assumes strictness fails immediately with a passing build on unknown input instead of failing fast.
{"case":{"believed":"A caller expects unknown YAML keys to be rejected by default when decoding into a typed struct.","caseId":"case:sha256:3c8f69bddbb54bd3bcead652e0657398830390f3969468693d0119ec23a94a24","contract":["assert Unmarshal succeeds when decoding `name: main\nunknown: value` into `decodeTarget` without options","assert the known `name` field decodes to `main` when unknown fields are present","assert adding `yaml.DisallowUnknownFields` as the JSON option makes the same input fail"],"goal":"Show that unknown fields are accepted by default when using `sigs.k8s.io/yaml.Unmarshal`","kind":"HOW","packages":["pkg:golang/sigs.k8s.io/yaml@v1.4.0"],"schemaVersion":1,"symbols":["sigs.k8s.io/yaml.Unmarshal","sigs.k8s.io/yaml.DisallowUnknownFields"]},"contractCommand":["go","test","./..."],"environment":{"arch":"x64","ecosystem":"golang","executionContext":"go","language":"go","os":"linux","packageManager":"golang","runtime":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/sigs.k8s.io/yaml@v1.4.0"],"schemaVersion":1,"symbols":["sigs.k8s.io/yaml.Unmarshal","sigs.k8s.io/yaml.DisallowUnknownFields"],"verifierAdapter":"golang@1"}
module example
go 1.22.0
require sigs.k8s.io/yaml v1.4.0
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
package example
import (
"testing"
yaml "sigs.k8s.io/yaml"
)
type decodeTarget struct {
Name string `json:"name"`
}
func TestUnmarshalAllowsUnknownByDefault(t *testing.T) {
const data = "name: main\nunknown: value\n"
var got decodeTarget
if err := yaml.Unmarshal([]byte(data), &got); err != nil {
t.Fatalf("unexpected error: %v", err)
}
if got.Name != "main" {
t.Fatalf("expected name=%q, got %q", "main", got.Name)
}
}
func TestUnmarshalDisallowUnknownFieldsFails(t *testing.T) {
const data = "name: main\nunknown: value\n"
var got decodeTarget
if err := yaml.Unmarshal([]byte(data), &got, yaml.DisallowUnknownFields); err == nil {
t.Fatalf("expected decode failure for unknown field when DisallowUnknownFields is supplied")
}
}