Skip to content

Commit

Permalink
Merge pull request #2690 from microsoftgraph/fix_special_characters_i…
Browse files Browse the repository at this point in the history
…nvokemgraph

Restricts escaping of special characters to path segments only when using Invoke-MgGraphRequest and bumps ``Azure.Identity.Broker`` Library
  • Loading branch information
timayabi2020 authored Apr 19, 2024
2 parents d6bd512 + b12715c commit 05b939d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
<LangVersion>9.0</LangVersion>
<TargetFrameworks>netstandard2.0;net6.0;net472</TargetFrameworks>
<RootNamespace>Microsoft.Graph.PowerShell.Authentication.Core</RootNamespace>
<Version>2.6.1</Version>
<Version>2.18.0</Version>
</PropertyGroup>
<PropertyGroup>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.11.0" />
<PackageReference Include="Azure.Identity.Broker" Version="1.0.0-beta.5" />
<PackageReference Include="Azure.Identity.Broker" Version="1.1.0" />
<PackageReference Include="Microsoft.Graph.Core" Version="3.0.9" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,7 @@ private Uri PrepareUri(HttpClient httpClient, Uri uri)
// set body to null to prevent later FillRequestStream
Body = null;
}
// TODO: Review the fix made in https://github.com/microsoftgraph/msgraph-sdk-powershell/pull/2455.
return uriBuilder.Uri;
return uriBuilder.Uri.EscapeDataStrings();
}

private void ThrowIfError(ErrorRecord error)
Expand Down
16 changes: 14 additions & 2 deletions src/Authentication/Authentication/Helpers/EncodeUriPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,25 @@ public static Uri EscapeDataStrings(this Uri uri)
int counter = 0;
var pathSegments = uri.OriginalString.Split('/');
StringBuilder sb = new StringBuilder();
foreach (var segment in pathSegments)
foreach (var s in pathSegments)
{
var segment = s;
//Skips the left part of the uri i.e https://graph.microsoft.com
if (counter > 2)
{
sb.Append('/');
sb.Append(Uri.EscapeDataString(segment));
if(s.Contains("?"))
{
var queryStringIndex = segment.IndexOf("?");
string queryString = segment.Substring(queryStringIndex);
segment = s.Substring(0, queryStringIndex);
sb.Append(Uri.EscapeDataString(segment));
sb.Append(queryString);
}
else
{
sb.Append(Uri.EscapeDataString(segment));
}
}
counter++;
}
Expand Down

0 comments on commit 05b939d

Please sign in to comment.