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 dbbe169ae3d..8ba9a7900ce 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 @@ -1799,7 +1799,7 @@ internal void ParseLinkHeader(HttpResponseMessage response, System.Uri requestUr _relationLink.Clear(); } - // we only support the URL in angle brackets and `rel`, other attributes are ignored + // We only support the URL in angle brackets and `rel`, other attributes are ignored // user can still parse it themselves via the Headers property const string pattern = "<(?.*?)>;\\s*rel=(?\")?(?(?(quoted).*?|[^,;]*))(?(quoted)\")"; IEnumerable links; @@ -1807,9 +1807,9 @@ internal void ParseLinkHeader(HttpResponseMessage response, System.Uri requestUr { foreach (string linkHeader in links) { - foreach (string link in linkHeader.Split(',')) + MatchCollection matchCollection = Regex.Matches(linkHeader, pattern); + foreach (Match match in matchCollection) { - Match match = Regex.Match(link, pattern); if (match.Success) { string url = match.Groups["url"].Value; diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 index 0a84f60cd76..5b6c0a988a9 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 @@ -2438,6 +2438,16 @@ Describe "Invoke-RestMethod tests" -Tags "Feature", "RequireAdminOnWindows" { 1..3 | ForEach-Object { $result.Output[$_ - 1].linknumber | Should -BeExactly $_ } } + It "Validate Invoke-RestMethod -FollowRelLink correctly manages commas" { + $maxLinks = 5 + $uri = Get-WebListenerUrl -Test 'Link' -Query @{maxlinks = $maxLinks; type = "with,comma"} + $command = "Invoke-RestMethod -Uri '$uri' -FollowRelLink" + $result = ExecuteWebCommand -command $command + + $result.Output.Count | Should -BeExactly $maxLinks + 1..$maxLinks | ForEach-Object { $result.Output[$_ - 1].linknumber | Should -BeExactly $_ } + } + It "Verify Invoke-RestMethod supresses terminating errors with -SkipHttpErrorCheck" { $uri = Get-WebListenerUrl -Test 'Response' -Query $NotFoundQuery $command = "Invoke-RestMethod -SkipHttpErrorCheck -Uri '$uri'"