Skip to content

Commit 05b939d

Browse files
authored
Merge pull request #2690 from microsoftgraph/fix_special_characters_invokemgraph
Restricts escaping of special characters to path segments only when using Invoke-MgGraphRequest and bumps ``Azure.Identity.Broker`` Library
2 parents d6bd512 + b12715c commit 05b939d

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/Authentication/Authentication.Core/Microsoft.Graph.Authentication.Core.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
<LangVersion>9.0</LangVersion>
55
<TargetFrameworks>netstandard2.0;net6.0;net472</TargetFrameworks>
66
<RootNamespace>Microsoft.Graph.PowerShell.Authentication.Core</RootNamespace>
7-
<Version>2.6.1</Version>
7+
<Version>2.18.0</Version>
88
</PropertyGroup>
99
<PropertyGroup>
1010
<EnableNETAnalyzers>true</EnableNETAnalyzers>
1111
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
1212
</PropertyGroup>
1313
<ItemGroup>
1414
<PackageReference Include="Azure.Identity" Version="1.11.0" />
15-
<PackageReference Include="Azure.Identity.Broker" Version="1.0.0-beta.5" />
15+
<PackageReference Include="Azure.Identity.Broker" Version="1.1.0" />
1616
<PackageReference Include="Microsoft.Graph.Core" Version="3.0.9" />
1717
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
1818
</ItemGroup>

src/Authentication/Authentication/Cmdlets/InvokeMgGraphRequest.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,7 @@ private Uri PrepareUri(HttpClient httpClient, Uri uri)
402402
// set body to null to prevent later FillRequestStream
403403
Body = null;
404404
}
405-
// TODO: Review the fix made in https://github.com/microsoftgraph/msgraph-sdk-powershell/pull/2455.
406-
return uriBuilder.Uri;
405+
return uriBuilder.Uri.EscapeDataStrings();
407406
}
408407

409408
private void ThrowIfError(ErrorRecord error)

src/Authentication/Authentication/Helpers/EncodeUriPath.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,25 @@ public static Uri EscapeDataStrings(this Uri uri)
1818
int counter = 0;
1919
var pathSegments = uri.OriginalString.Split('/');
2020
StringBuilder sb = new StringBuilder();
21-
foreach (var segment in pathSegments)
21+
foreach (var s in pathSegments)
2222
{
23+
var segment = s;
2324
//Skips the left part of the uri i.e https://graph.microsoft.com
2425
if (counter > 2)
2526
{
2627
sb.Append('/');
27-
sb.Append(Uri.EscapeDataString(segment));
28+
if(s.Contains("?"))
29+
{
30+
var queryStringIndex = segment.IndexOf("?");
31+
string queryString = segment.Substring(queryStringIndex);
32+
segment = s.Substring(0, queryStringIndex);
33+
sb.Append(Uri.EscapeDataString(segment));
34+
sb.Append(queryString);
35+
}
36+
else
37+
{
38+
sb.Append(Uri.EscapeDataString(segment));
39+
}
2840
}
2941
counter++;
3042
}

0 commit comments

Comments
 (0)