fix: TypeKVPairs to handle multiple comma-separated pairs #31624
+92
−0
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.
Description
This PR fixes a bug in
framework.TypeKVPairswhere comma-separated key-value pair strings are incorrectly parsed as a single pair instead of multiple pairs.Input:
"A=a,B=b,C=c"Expected Output:
map[A:a B:b C:c](3 pairs)Actual Output:
map[A:a,B=b,C=c](1 pair)Problem
The
TypeKVPairsfield type only parses the first key-value pair from a comma-separated string, treating everything after the first=sign as a single value. This contradicts the type name and the official documentation infield_type.gowhich states:The phrase "a list of" (plural) clearly indicates support for multiple key-value pairs, not just a single pair.
Related
Fixes #31621
Reproduction
Consider the following test case
Output Before Fix
Root Cause
In
sdk/framework/field_data.go, when parsingTypeKVPairs, the code usesmapstructure.WeakDecodeto decode the raw input as a string slice. When a single comma-separated string is provided,mapstructuretreats it as a single-element slice:The subsequent loop only processes this single element, splitting it at the first
=:Solution
Add logic to detect when
listResultcontains a single comma-separated string and split it into individual key-value pairs before processing:Additionally, trim whitespace from each pair to handle formats like
"A=a, B=b".Changes
sdk/framework/field_data.go: Added comma-splitting logic for single-element string slices in theTypeKVPairscase, plus whitespace trimming in the parsing loopsdk/framework/field_data_test.go: Added comprehensive test cases.Output after the Fix
map[key1:value1 key2:value2 key3:value3] // 3 separate pairs
Breaking Changes
None. This fix maintains full backward compatibility:
"A=a"→{"A": "a"}{"A": "a", "B": "b"}→{"A": "a", "B": "b"}["A=a", "B=b"]→{"A": "a", "B": "b"}The fix only applies comma-splitting when a single-element list contains commas, ensuring existing behavior is preserved.
Revert plan: This change can be safely reverted by reverting this PR. No data migration, configuration changes, or additional steps required.
Security impact: No changes to security controls. This is a pure parsing bug fix in the SDK framework that does not affect access control, logging, authentication, or any security mechanisms. The change only affects how string input is parsed into key-value pairs.
PCI review checklist
Examples of changes to security controls include using new access control methods, adding or removing logging pipelines, etc.