fix: parse Link rel="alternate" in any parameter position#77
Draft
fix: parse Link rel="alternate" in any parameter position#77
Conversation
The _parse_link_alternates regex required rel="alternate" to appear immediately after the first semicolon following the URI-Reference. This meant Link headers with other parameters before rel (e.g., title, type) would silently fail to match, violating RFC 8288 section 3 which allows parameters in any order. Split the match into two steps: check for rel="alternate" anywhere in the link value, then extract the URI. Also makes the match case-insensitive per RFC 8288 section 2.1.1. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What: Fix
_parse_link_alternatesto matchrel="alternate"regardless of its position among Link header parameters.Why: The regex required
rel="alternate"immediately after the first;, so a header like<url>; title="cross-signed"; rel="alternate"silently failed to match. RFC 8288 section 3 allows parameters in any order. While current Let's Encrypt responses putrelfirst, other CAs may not — and the spec doesn't require it.How: Split into two regex steps: first check
;\s*rel="alternate"anywhere in the value (case-insensitive per RFC 8288 §2.1.1), then extract the URI from<...>. This is a superset of #72 (which only adds case-insensitivity).Testing: 13 test cases covering: no header, single/multiple alternates, non-alternate filtering, case variations, whitespace, and — the new cases —
relappearing after other params liketitleortype.🤖 Generated with Claude Code