Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1799,17 +1799,17 @@ 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 = "<(?<url>.*?)>;\\s*rel=(?<quoted>\")?(?<rel>(?(quoted).*?|[^,;]*))(?(quoted)\")";
IEnumerable<string> links;
if (response.Headers.TryGetValues("Link", out links))
{
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
Expand Down