Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes sanitazation of date and time values in path/query parameters #143

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 43 additions & 0 deletions Microsoft.Kiota.Abstractions.Tests/RequestInformationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, object>
{
{ "%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<string, object>
{
{ "%24time", time }
};

requestInfo.PathParameters = pathParameters;

// Assert
Assert.Contains($"%24time=06%3A00%3A00", requestInfo.URI.OriginalString);
}
[Fact]
public void ThrowsInvalidOperationExceptionWhenBaseUrlNotSet()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Kiota.Abstractions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageProjectUrl>https://aka.ms/kiota/docs</PackageProjectUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<Deterministic>true</Deterministic>
<VersionPrefix>1.6.0</VersionPrefix>
<VersionPrefix>1.6.1</VersionPrefix>
<VersionSuffix></VersionSuffix>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<SignAssembly>false</SignAssembly>
Expand Down
2 changes: 2 additions & 0 deletions src/RequestInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
};

Expand Down