diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs index fcabe09c18..8f1c6a4caf 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs @@ -1616,7 +1616,8 @@ namespace Microsoft.PowerShell.Commands { if (_relationLink == null) { - _relationLink = new Dictionary(); + // Must ignore the case of relation links. See RFC 8288 (https://tools.ietf.org/html/rfc8288) + _relationLink = new Dictionary(StringComparer.OrdinalIgnoreCase); } else { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 index 27087ccb9e..22e3733484 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 @@ -733,6 +733,28 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { $result.Output.RelationLink["self"] | Should -BeExactly "${baseUri}?maxlinks=5&linknumber=2&type=multiple" } + + It "Validate Invoke-WebRequest RelationLink keys are treated case-insensitively" { + $uri = Get-WebListenerUrl -Test 'Link' -Query @{maxlinks = 5; linknumber = 2; type = 'multiple'} + $command = "Invoke-WebRequest -Uri '$uri'" + $result = ExecuteWebCommand -command $command + + $result.Output.RelationLink["next"] | Should -Not -BeNullOrEmpty + $result.Output.RelationLink["next"] | Should -BeExactly $result.Output.RelationLink["Next"] + + $result.Output.RelationLink["last"] | Should -Not -BeNullOrEmpty + $result.Output.RelationLink["last"] | Should -BeExactly $result.Output.RelationLink["LAST"] + + $result.Output.RelationLink["prev"] | Should -Not -BeNullOrEmpty + $result.Output.RelationLink["prev"] | Should -BeExactly $result.Output.RelationLink["preV"] + + $result.Output.RelationLink["first"] | Should -Not -BeNullOrEmpty + $result.Output.RelationLink["first"] | Should -BeExactly $result.Output.RelationLink["FiRsT"] + + $result.Output.RelationLink["self"] | Should -Not -BeNullOrEmpty + $result.Output.RelationLink["self"] | Should -BeExactly $result.Output.RelationLink["self"] + } + It "Validate Invoke-WebRequest quietly ignores invalid Link Headers in RelationLink property: " -TestCases @( @{ type = "noUrl" } @{ type = "malformed" }