Skip to content

Commit

Permalink
Merge pull request #143 from microsoft/andrueastman/dateTimeUrls
Browse files Browse the repository at this point in the history
Fixes sanitazation of date and time values
  • Loading branch information
andrueastman committed Nov 2, 2023
2 parents 9b60161 + 715944e commit cb74135
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
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

0 comments on commit cb74135

Please sign in to comment.