Repository navigation
Preserve empty attributes when parsing composite keys - #646
Open
RaphaelFakhri wants to merge 1 commit into
Open
RaphaelFakhri wants to merge 1 commit into
RaphaelFakhri wants to merge 1 commit into
Conversation
CompositeKey.parseCompositeKey() split the key with String.split(delimiter, 0), which discards trailing empty strings. Empty trailing attributes were lost, so the parsed key no longer matched the original ledger key, and a composite key with an empty object type and no attributes failed with an ArrayIndexOutOfBoundsException. The Go and Node shims keep these attributes. Signed-off-by: Raphael Fakhri <153192858+RaphaelFakhri@users.noreply.github.com>
|
This branch has not been deployed
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.



CompositeKey.parseCompositeKey(), used byChaincodeStub.splitCompositeKey(), splits the key withString.split(delimiter, 0). That call discards trailing empty strings, so empty attributes at the end of a key are lost:\u0000abc\u0000\u0000def\u0000\u0000\u0000parses to the attributes["", "def"]instead of["", "def", "", ""], andtoString()on the result no longer returns the original ledger key.\u0000\u0000(empty object type, no attributes) throwsArrayIndexOutOfBoundsException.This change splits with a negative limit to keep empty segments and drops only the empty segment after the final delimiter. The behavior now matches the Go and Node shims. Keys without empty attributes parse as before.
Tests added in
CompositeKeyTestcover empty middle and trailing attributes and an empty object type, including the round trip throughtoString().Closes #645