Repository navigation
fix(serialization-text): defensive byte array and timespan parsing in TextParseNode - #855
Merged
Vincent Biret (baywet) merged 8 commits intoNov 9, 2026
Conversation
…ode.GetByteArrayValue Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
… in TextParseNode Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…eNode.GetTimeSpanValue Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
… parsing Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…erflowException in GetTimeSpanValue Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…-of-range TimeSpan durations Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…eArray and TimeSpan in TextParseNode Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
Contributor
Author
|
While working with TextParseNode, I noticed a couple of edge cases in primitive parsing that differed from the defensive conventions used across other Kiota parse nodes (like JsonParseNode and FormParseNode):
This PR adds:
All tests pass locally across all target frameworks ( |
Copilot stopped reviewing on behalf of
Vincent Biret (baywet) due to an error
November 9, 2026 18:16
… null check in GetTimeSpanValue - Remove special-case check for 'null' string so unparseable strings follow normal parsing flow. - Catch FormatException and OverflowException directly rather than filtering Exception with when clause. Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
Contributor
Author
|
Hi Vincent Biret (@baywet), pushed an update addressing the review comments:
All tests across target frameworks and formatting checks continue to pass cleanly. Ready for another look! |
Vincent Biret (baywet)
approved these changes
Nov 9, 2026
This was referenced Nov 17, 2026
Bump Microsoft.Kiota.Abstractions and 6 others
tabrezahmed51/microsoft_kiota_sdk_opensource_0118#287
Open
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.

Description
This PR enhances defensive parsing behavior in
TextParseNode(Microsoft.Kiota.Serialization.Text) to align with other Kiota parse node implementations (such asJsonParseNodeandFormParseNode):Defensive Byte Array Parsing (
GetByteArrayValue):GetByteArrayValue()on an unparseable or malformed Base-64 string threw an unhandledFormatException.TextParseNodeand peer parse nodes defensively catch format exceptions and returnnull.Convert.FromBase64Stringwith atry-catchforFormatExceptionto safely returnnullon invalid Base-64 payloads.Standard TimeSpan Format Support & Defensive Parsing (
GetTimeSpanValue):GetTimeSpanValue()to support standard constant format ("c", e.g.,"01:02:03"/"1.02:03:04") viaTimeSpan.TryParseExact(..., "c", ...)in addition to ISO 8601 duration format (XmlConvert.ToTimeSpan).try-catchhandling forFormatExceptionandOverflowExceptionthrown byXmlConvert.ToTimeSpanon malformed or out-of-range strings, returningnullconsistently.Changes
src/serialization/text/TextParseNode.cs:try-catchonConvert.FromBase64StringinGetByteArrayValue()."c"format parsing, and exception guards (FormatException,OverflowException) inGetTimeSpanValue().tests/serialization/text/TextParseNodeTests.cs:ReturnsNullOnInvalidByteArraytest covering invalid Base-64 strings and empty strings.ParsesConstantTimeSpantest covering standard TimeSpan string formats ("01:02:03","1.02:03:04","-00:05:00").ReturnsNullOnMalformedOrOutOfRangeTimeSpantest covering malformed durations and out-of-range durations.Verification
dotnet testpassed 100% across all target frameworks (net10.0,net8.0,net472).dotnet format --verify-no-changespassed with 0 violations.