From 715944e2e574f8690c721c6d6ec0a4c7d574f64c Mon Sep 17 00:00:00 2001 From: Andrew Omondi Date: Thu, 2 Nov 2023 15:42:25 +0300 Subject: [PATCH] Fixes sanitazation of date and time values --- CHANGELOG.md | 6 +++ .../RequestInformationTests.cs | 43 +++++++++++++++++++ src/Microsoft.Kiota.Abstractions.csproj | 2 +- src/RequestInformation.cs | 2 + 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2f8072a..6cab8262 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.6.1] - 2023-11-02 + +### Changed + +- Fixes sanitization of Date and Time values in query and path parameters + ## [1.6.0] - 2023-10-31 ### Added diff --git a/Microsoft.Kiota.Abstractions.Tests/RequestInformationTests.cs b/Microsoft.Kiota.Abstractions.Tests/RequestInformationTests.cs index be4cd9d8..292bfdac 100644 --- a/Microsoft.Kiota.Abstractions.Tests/RequestInformationTests.cs +++ b/Microsoft.Kiota.Abstractions.Tests/RequestInformationTests.cs @@ -195,7 +195,50 @@ public void SetsPathParametersOfGuidType() // Assert Assert.Contains($"%24requestId=6d320a89-2d8f-4204-855d-b98a1bc176d4", requestInfo.URI.OriginalString); } + [Fact] + public void SetsPathParametersOfDateType() + { + // Arrange as the request builders would + var requestInfo = new RequestInformation + { + HttpMethod = Method.GET, + UrlTemplate = "http://localhost/users{?%24date}" + }; + // Act + var date = new Date(2023,10,26); + var pathParameters = new Dictionary + { + { "%24date", date } + }; + + requestInfo.PathParameters = pathParameters; + + // Assert + Assert.Contains($"%24date=2023-10-26", requestInfo.URI.OriginalString); + } + [Fact] + public void SetsPathParametersOfTimeType() + { + // Arrange as the request builders would + var requestInfo = new RequestInformation + { + HttpMethod = Method.GET, + UrlTemplate = "http://localhost/users{?%24time}" + }; + + // Act + var time = new Time(6,0,0); + var pathParameters = new Dictionary + { + { "%24time", time } + }; + + requestInfo.PathParameters = pathParameters; + + // Assert + Assert.Contains($"%24time=06%3A00%3A00", requestInfo.URI.OriginalString); + } [Fact] public void ThrowsInvalidOperationExceptionWhenBaseUrlNotSet() { diff --git a/src/Microsoft.Kiota.Abstractions.csproj b/src/Microsoft.Kiota.Abstractions.csproj index aea567dd..5593b156 100644 --- a/src/Microsoft.Kiota.Abstractions.csproj +++ b/src/Microsoft.Kiota.Abstractions.csproj @@ -14,7 +14,7 @@ https://aka.ms/kiota/docs true true - 1.6.0 + 1.6.1 true false diff --git a/src/RequestInformation.cs b/src/RequestInformation.cs index d3f772da..930f82b1 100644 --- a/src/RequestInformation.cs +++ b/src/RequestInformation.cs @@ -81,6 +81,8 @@ public Uri URI DateTimeOffset dateTimeOffset => dateTimeOffset.ToString("o"),// Default to ISO 8601 for datetimeoffsets in the url. DateTime dateTime => dateTime.ToString("o"),// Default to ISO 8601 for datetimes in the url. Guid guid => guid.ToString("D"),// Default of 32 digits separated by hyphens + Date date => date.ToString(), //Default to string format of the custom date object + Time time => time.ToString(), //Default to string format of the custom time object _ => value,//return object as is as the ToString method is good enough. };