Make relation-link handling in web cmdlets case insensitive (#6338)

This commit is contained in:
rjmholt
2018-03-08 15:54:42 -08:00
committed by Dongbo Wang
parent 6d191970c5
commit e42c1db395
2 changed files with 24 additions and 1 deletions
@@ -1616,7 +1616,8 @@ namespace Microsoft.PowerShell.Commands
{
if (_relationLink == null)
{
_relationLink = new Dictionary<string, string>();
// Must ignore the case of relation links. See RFC 8288 (https://tools.ietf.org/html/rfc8288)
_relationLink = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
}
else
{
@@ -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: <type>" -TestCases @(
@{ type = "noUrl" }
@{ type = "malformed" }