Fix: prevent panic when using named string types as map keys#298
Merged
inhere merged 1 commit intogookit:masterfrom Jul 29, 2025
Merged
Fix: prevent panic when using named string types as map keys#298inhere merged 1 commit intogookit:masterfrom
inhere merged 1 commit intogookit:masterfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
Fixes a panic that occurred when using named string types as map keys in reflection-based validation by replacing a force type assertion with the String() method.
- Replaces force type assertion
val.(string)withkey.String()method call - Adds test coverage with a
CustomStringtype and corresponding map field - Prevents runtime panic when validation encounters maps with named string keys
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| data_source.go | Replaces force type assertion with key.String() to safely handle named string types |
| validation_test.go | Adds CustomString type definition and map field for testing |
| data_source_test.go | Adds test data using the new CustomString map field |
Pull Request Test Coverage Report for Build 16566182440Details
💛 - Coveralls |
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.
In reflection-based validation we were force‑casting map values to string, which panicked if the key wasn’t a raw string but a named string:
val = strings.ReplaceAll(val.(string), "\"", "") //nolint:forcetypeassertBy switching to
key.String(), we obtain the textual form of any named string key without a type assertion.