Repository navigation
Report an unhashable merged key as an error, not a panic - #19
Merged
Merged
Conversation
A mapping being merged has each of its keys looked up among the keys
already seen, before the check that rejects a map or a sequence as a
key. Hashing one of those panics, so a document like
<<:
? [1]
: v
1: x
took down the caller instead of returning an error. Guard the lookup and
the store the way go-yaml does upstream, which turns the panic into an
ordinary yaml error.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017e285CvofYf6joqC98gTXz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A mapping being merged has each of its keys looked up among the keys already seen, before the check that rejects a map or a sequence as a key. Hashing one of those panics, so this document took down the caller instead of returning an error:
The sibling
1: xmatters only because it makes the target amap[interface{}]interface{}, which is what a string-keyed decode would have rejected earlier.The guard is a port of what go-yaml does upstream (
setPossiblyUnhashableKey/getPossiblyUnhashableKey, present in go.yaml.in/yaml/v3 and absent from the v3.0.1 line this fork is based on), so the behaviour now matches: an ordinaryyaml:error naming the unhashable type.Found by fuzzing kin-openapi's loader, where the same document panicked inside
LoadFromData. With this change the loader returns an error.Tests: two cases added to
unmarshalErrorTests, so both theUnmarshaland theDecoderpaths cover them. Full suite passes, including-race.🤖 Generated with Claude Code
https://claude.ai/code/session_017e285CvofYf6joqC98gTXz