8000 [Feature] Make relation-link handling in web cmdlets case insensitive · PowerShell/PowerShell@e598800 · GitHub
[go: up one dir, main page]

Skip to content

Commit e598800

Browse files
committed
[Feature] Make relation-link handling in web cmdlets case insensitive
1 parent d56c191 commit e598800

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,8 @@ internal void ParseLinkHeader(HttpResponseMessage response, System.Uri requestUr
16161616
{
16171617
if (_relationLink == null)
16181618
{
1619-
_relationLink = new Dictionary<string, string>();
1619+
// Must ignore the case of relation links. See RFC 8288 (https://tools.ietf.org/html/rfc8288)
1620+
_relationLink = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
16201621
}
16211622
else
16221623
{

test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,28 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" {
733733
$result.Output.RelationLink["self"] | Should -BeExactly "${baseUri}?maxlinks=5&linknumber=2&type=multiple"
734734
}
735735

736+
737+
It "Validate Invoke-WebRequest RelationLink keys are treated case-insensitively" {
738+
$uri = Get-WebListenerUrl -Test 'Link' -Query @{maxlinks = 5; linknumber = 2; type = 'multiple'}
739+
$command = "Invoke-WebRequest -Uri '$uri'"
740+
$result = ExecuteWebCommand -command $command
741+
742+
$result.Output.RelationLink["next"] | Should -Not -BeNullOrEmpty
743+
$result.Output.RelationLink["next"] | Should -BeExactly $result.Output.RelationLink["Next"]
744+
745+
$result.Output.RelationLink["last"] | Should -Not -BeNullOrEmpty
746+
$result.Output.RelationLink["last"] | Should -BeExactly $result.Output.RelationLink["LAST"]
747+
748+
$result.Output.RelationLink["prev"] | Should -Not -BeNullOrEmpty
< 7E0C code>749+
$result.Output.RelationLink["prev"] | Should -BeExactly $result.Output.RelationLink["preV"]
750+
751+
$result.Output.RelationLink["first"] | Should -Not -BeNullOrEmpty
752+
$result.Output.RelationLink["first"] | Should -BeExactly $result.Output.RelationLink["FiRsT"]
753+
754+
$result.Output.RelationLink["self"] | Should -Not -BeNullOrEmpty
755+
$result.Output.RelationLink["self"] | Should -BeExactly $result.Output.RelationLink["self"]
756+
}
757+
736758
It "Validate Invoke-WebRequest quietly ignores invalid Link Headers in RelationLink property: <type>" -TestCases @(
737759
@{ type = "noUrl" }
738760
@{ type = "malformed" }

0 commit comments

Comments
 (0)
0