Repository navigation
fix(serialization-text): preserve empty string and bytes values and handle malformed inputs - #840
Open
Hardik K (hardikkaurani) wants to merge 2 commits into
Conversation
…andle malformed inputs Allow empty strings and byte arrays to be serialized and deserialized in TextSerializationWriter and TextParseNode. Prevent silent duplicate value overwrites when the existing writer value is empty, and safely return None for malformed scalar primitives, invalid base64 bytes, and unknown enum members. Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…med scalars Add unit tests verifying serialization and deserialization of empty strings and empty bytes, assertion of duplicate write prevention on empty string, and safe None returns on malformed scalar primitives and unknown enums. Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.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.



Overview
Allow empty strings (
"") and empty byte arrays (b"") to be serialized and deserialized inTextSerializationWriterandTextParseNode, prevent duplicate write overwrites when existing writer content is empty, and safely handle invalid/malformed scalar inputs without uncaught exceptions.Changes
TextSerializationWriter.write_str_valueandget_serialized_contentpreviously checked the truthiness ofself._writer(if self._writer:) instead ofis not None. As a result, writing an empty string""causedget_serialized_content()to raiseNo content was written to the serialization writer, while writing a second value after""bypassed duplicate write rejection and silently overwrote the payload.TextSerializationWriter.write_bytes_valuenow checksvalue is not None and not key, properly base64-encoding and serializingb""and raisingNO_STRUCTURED_DATA_MESSAGEif a key is passed with empty bytes.TextParseNode.get_str_valuepreviously returnedNoneforTextParseNode("")due to truthiness evaluation (if self._text:). It now checksself._text is not None, correctly returning"".TextParseNodenow returnsNoneinstead of raising unhandled exceptions (ValueError,binascii.Error,KeyError) when encountering malformed primitives (int, float, UUID, datetime, date, time, timedelta), invalid base64 byte sequences, or unknown enum members, aligning withJsonParseNodeandFormParseNode.Related Issue
None (discovered during code audit of text serialization).
Testing Instructions
packages/serialization/text:pytest: 72 passed (58 existing + 14 new regression tests).mypy kiota_serialization_text: Clean (strict mode).isort --check-only kiota_serialization_text: Clean.yapf -dr kiota_serialization_text: Clean.pylint kiota_serialization_text --disable=W --rcfile=.pylintrc: Rated 10.00/10.packages/abstractions:pytest: 194 passed.