Repository navigation
fix: add reverse prefix matching for Accept-Language (RFC 4647 §3.4) - #115
Merged
Merged
Conversation
The scoring function only truncated the available tag to find a matching range in accepts (e.g. available "en-gb" tries "en"). The reverse — accept range "en" matching available "en-gb" — was missing. Add a second pass that checks if any accept range is a prefix of the available tag. Also fix wildcard "*" handling to use the actual q value from the accepts map instead of a hardcoded 0.01. Closes #111 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Move range + "-" concatenation outside the per-tag scoring lambda into a pre-computed List<RangePrefix>. Avoids a string allocation per accept entry per available tag during language negotiation. Co-Authored-By: Claude Opus 4.6 (1M context) <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.
Summary
"en"now matches available tag"en-gb"per RFC 4647 §3.4 Basic Filtering"*"handling to use the actualqvalue from the accepts map instead of hardcoded 0.01"en-gb"still tries"en-gb"then"en"in acceptsPreviously,
Accept-Language: enwith available["en-gb"]returnednull. Now correctly returns"en-gb".Closes #111
Test plan
acceptLanguageRangeMatchesMoreSpecificTag—Accept-Language: enwith available["en-gb"]→"en-gb"acceptLanguageRangeWithQuality—en;q=0.5, fr;q=1.0with available["en-gb", "fr-ca"]→"fr-ca"acceptLanguageExactMatchPreferredOverPrefixMatch— exacten-gb;q=0.9beats prefixen;q=0.5onen-usacceptLanguageWildcardStillWorks—Accept-Language: *returns a result🤖 Generated with Claude Code