fix: consistency on treating invalid strings #175
Merged
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 proto.Unmarshal, the SDK will remove any UTF-8 Null-Terminated String (0x00) from the string or []string value. To make consistency on how we should treat strings, all functions or methods that returning strings should return strings without
0x00
, and all functions or methods that validate invalid strings should check for both empty string and0x00
, invalid if the result of this is true ->value == "" || value == "\x00"
.Value marshaler will check whether a string is end with
0x00
, if it does not end with0x00
will automatically add it. If the users intentionally add multiple0x00
it should allow it. In cases where message definitions differ only slightly, such as when creating FieldDescription messages with minor variations in the FieldName value (type: []string), it make sense to add0x00
padding so that the length of the strings (the byte size of the FieldName value) become the same, this will reduce message definition interleave as it can be treated using the same message definition.