Skip to content

Commit

Permalink
Merge pull request #130 from timandella/timanndella/issue128
Browse files Browse the repository at this point in the history
fix: issue 128 - Added sanitization for guid
  • Loading branch information
andrueastman authored Sep 25, 2023
2 parents e02c9e5 + 7e3a5aa commit cd20a6a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.3.3] - 2023-09-25

### Changed

- Removed the code that changed the first character of the query parameter name to lower case
- Added sanitization of guid values in query parameters

## [1.3.2] - 2023-09-21

Expand Down
25 changes: 25 additions & 0 deletions Microsoft.Kiota.Abstractions.Tests/RequestInformationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,28 @@ public void SetsPathParametersOfBooleanType()
// Assert
Assert.Contains("%24count=true", requestInfo.URI.OriginalString);
}
[Fact]
public void SetsPathParametersOfGuidType()
{
// Arrange as the request builders would
var requestInfo = new RequestInformation
{
HttpMethod = Method.GET,
UrlTemplate = "http://localhost/users{?%24requestId}"
};

// Act
var guid = Guid.Parse("6d320a89-2d8f-4204-855d-b98a1bc176d4");
var pathParameters = new Dictionary<string, object>
{
{ "%24requestId", guid }
};

requestInfo.PathParameters = pathParameters;

// Assert
Assert.Contains($"%24requestId=6d320a89-2d8f-4204-855d-b98a1bc176d4", requestInfo.URI.OriginalString);
}

[Fact]
public void ThrowsInvalidOperationExceptionWhenBaseUrlNotSet()
Expand Down Expand Up @@ -389,6 +411,9 @@ internal class GetQueryParameters
/// <summary>Select properties to be returned</summary>\
[QueryParameter("%24select")]
public string[] Select { get; set; }
/// <summary>Unique id of the request</summary>
[QueryParameter("%24requestId")]
public Guid RequestId { get; set; }
/// <summary>Include count of items</summary>
[QueryParameter("%24count")]
public bool? Count { get; set; }
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.3.2</VersionPrefix>
<VersionPrefix>1.3.3</VersionPrefix>
<VersionSuffix></VersionSuffix>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<SignAssembly>false</SignAssembly>
Expand Down
1 change: 1 addition & 0 deletions src/RequestInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public Uri URI
bool boolean => boolean.ToString().ToLower(),// pass in a lowercase string as the final url will be uppercase due to the way ToString() works for booleans
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
_ => value,//return object as is as the ToString method is good enough.
};

Expand Down

0 comments on commit cd20a6a

Please sign in to comment.