Repository navigation
Closed
Labels
Issue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.The issue is fixed.WG-Cmdletsgeneral cmdlet issuesgeneral cmdlet issues
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
Using Invoke-RestMethod with -FollowRelLink works when the server returns a Link header with relation type rel="next", but not when the relation type is rel=next without quotes, although the Web Linking RFC allows it. Quotes are only required under specific circumstances, never for IANA relation types.
relation-types = relation-type
| <"> relation-type *( 1*SP relation-type ) <">
relation-type = reg-rel-type | ext-rel-type
reg-rel-type = LOALPHA *( LOALPHA | DIGIT | "." | "-" )
ext-rel-type = URI
Note that extension relation types are REQUIRED to be absolute URIs in Link headers, and MUST be quoted if they contain a semicolon (";") or comma (",") (as these characters are used as delimiters in the header itself).
The Regex pattern can be found here.
Line 1833 in e70ad6c
| const string pattern = "<(?<url>.*?)>;\\s*rel=(\"?)(?<rel>.*?)\\1[^\\w -.]?"; |
Expected behavior
PS> Invoke-RestMethod "https://api.guildwars2.com/v2/quaggans?page=0&page_size=10" -FollowRelLink
id url
-- ---
404 https://static.staticwars.com/quaggans/404.jpg
aloha https://static.staticwars.com/quaggans/aloha.jpg
attack https://static.staticwars.com/quaggans/attack.jpg
bear https://static.staticwars.com/quaggans/bear.jpg
bowl https://static.staticwars.com/quaggans/bowl.jpg
box https://static.staticwars.com/quaggans/box.jpg
breakfast https://static.staticwars.com/quaggans/breakfast.jpg
bubble https://static.staticwars.com/quaggans/bubble.jpg
cake https://static.staticwars.com/quaggans/cake.jpg
cheer https://static.staticwars.com/quaggans/cheer.jpg
coffee https://static.staticwars.com/quaggans/coffee.jpg
construction https://static.staticwars.com/quaggans/construction.jpg
cow https://static.staticwars.com/quaggans/cow.jpg
cry https://static.staticwars.com/quaggans/cry.jpg
elf https://static.staticwars.com/quaggans/elf.jpg
ghost https://static.staticwars.com/quaggans/ghost.jpg
girl https://static.staticwars.com/quaggans/girl.jpg
hat https://static.staticwars.com/quaggans/hat.jpg
helmut https://static.staticwars.com/quaggans/helmut.jpg
hoodie-down https://static.staticwars.com/quaggans/hoodie-down.jpg
hoodie-up https://static.staticwars.com/quaggans/hoodie-up.jpg
killerwhale https://static.staticwars.com/quaggans/killerwhale.jpg
knight https://static.staticwars.com/quaggans/knight.jpg
lollipop https://static.staticwars.com/quaggans/lollipop.jpg
lost https://static.staticwars.com/quaggans/lost.jpg
moving https://static.staticwars.com/quaggans/moving.jpg
party https://static.staticwars.com/quaggans/party.jpg
present https://static.staticwars.com/quaggans/present.jpg
quaggan https://static.staticwars.com/quaggans/quaggan.jpg
rain https://static.staticwars.com/quaggans/rain.jpg
scifi https://static.staticwars.com/quaggans/scifi.jpg
seahawks https://static.staticwars.com/quaggans/seahawks.jpg
sleep https://static.staticwars.com/quaggans/sleep.jpg
summer https://static.staticwars.com/quaggans/summer.jpg
vacation https://static.staticwars.com/quaggans/vacation.jpgActual behavior
PS> Invoke-RestMethod "https://api.guildwars2.com/v2/quaggans?page=0&page_size=10" -FollowRelLink
id url
-- ---
404 https://static.staticwars.com/quaggans/404.jpg
aloha https://static.staticwars.com/quaggans/aloha.jpg
attack https://static.staticwars.com/quaggans/attack.jpg
bear https://static.staticwars.com/quaggans/bear.jpg
bowl https://static.staticwars.com/quaggans/bowl.jpg
box https://static.staticwars.com/quaggans/box.jpg
breakfast https://static.staticwars.com/quaggans/breakfast.jpg
bubble https://static.staticwars.com/quaggans/bubble.jpg
cake https://static.staticwars.com/quaggans/cake.jpg
cheer https://static.staticwars.com/quaggans/cheer.jpgError details
No response
Environment data
Name Value
---- -----
PSVersion 7.1.4
PSEdition Core
GitCommitId 7.1.4
OS Microsoft Windows 10.0.19043
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0Visuals
Metadata
Metadata
Assignees
Labels
Issue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.The issue is fixed.WG-Cmdletsgeneral cmdlet issuesgeneral cmdlet issues

Activity
sliekens commentedon Aug 22, 2021
This is caused by the lazy
.*?expression in the rel capturing group. If the numbered capturing group for the quote is empty, then the rel named group will also be empty (because the shortest possible match for.*is the empty string itself).I came up with this pattern that uses conditional expressions instead of trying to match an empty capturing group.
I tested the pattern with quotes and without quotes, both work now.
With quotes
Without quotes
Fix parsing Link headers with unquoted rel types