Repository navigation
tighten language tag parsing - #11
Conversation
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cc7ac18404
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if !is_variant_subtag(part) { | ||
| return error('language tag has an invalid subtag') |
There was a problem hiding this comment.
Accept valid BCP 47 extension sequences
This rejects every extension singleton because u (or any other singleton) is not a variant; for example, the valid tag en-u-ca now makes new_bundle/add_messages fail and is silently discarded from an Accept-Language preference. The previous parser accepted these tags, so the stricter validation should recognize extension sequences rather than classifying them as malformed.
Useful? React with 👍 / 👎.
| if index > 0 && part.len == 4 && is_language_subtag_alpha(part) { | ||
| return part[0..1].to_upper() + part[1..].to_lower() |
There was a problem hiding this comment.
Restrict script casing to the script position
The length/index check also treats four-letter private-use subtags as scripts. Consequently, parse_language_tag('en-x-latn').str() changed from en-x-latn to en-x-Latn, even though subtags following x are private-use values and should remain lowercase in the canonical display. Track whether the subtag is the actual script field before applying title case.
Useful? React with 👍 / 👎.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 01a2b02966
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return LanguageTag{ | ||
| parts: tag.parts[..private_index].clone() |
There was a problem hiding this comment.
Preserve intermediate private-use parents
When both en-x-foo and a less specific default such as en are registered, a request for en-x-foo-bar now jumps directly to en, so the closer en-x-foo translation is never considered. Lookup is supposed to truncate one trailing private-use subtag at a time, removing x only when it becomes terminal, as illustrated by RFC 4647's fallback sequence; avoid slicing off the entire private-use section here.
Useful? React with 👍 / 👎.
| if !is_variant_subtag(part) { | ||
| return error('language tag has an invalid subtag') |
There was a problem hiding this comment.
Continue accepting grandfathered language tags
For the valid grandfathered BCP 47 tag en-GB-oed, parsing reaches this branch and rejects the three-letter oed component as a non-variant. RFC 5646 explicitly includes en-GB-oed in the grandfathered production, and the previous parser accepted it; because its base language is supported, existing add_messages('en-GB-oed', ...) calls and corresponding message files now fail. Recognize grandfathered tags before applying the regular langtag grammar.
Useful? React with 👍 / 👎.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 48ceb5cb99
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| mut index := 1 | ||
| if index < parts.len && is_script_subtag(parts[index]) { |
There was a problem hiding this comment.
Consume extlangs before script and region
For a tag containing an extended-language subtag, such as zh-cmn-Hans-CN, this starts looking for the script at cmn without first consuming the extlang, so cmn eventually reaches the variant check and the valid tag is rejected. RFC 5646 places up to three extlang subtags between a 2–3-letter primary language and the script; recognize that sequence before checking the script and ensure display indexing skips it as well.
Useful? React with 👍 / 👎.
| if !is_language_subtag_alpha(parts[0]) || parts[0].len < 2 || parts[0].len > 8 { | ||
| return error('language tag has an invalid language subtag') |
There was a problem hiding this comment.
Accept tags composed entirely of private use
When the input is a private-use-only tag such as x-company, this primary-language check rejects the leading x before the later private-use handling can run. RFC 5646 explicitly permits Language-Tag = privateuse and tags consisting entirely of private-use subtags, and the previous parser accepted these inputs; callers now receive an error, while parse_language_preferences silently drops the preference.
Useful? React with 👍 / 👎.
| if index < parts.len && is_region_subtag(parts[index]) { | ||
| region_index = index | ||
| } |
There was a problem hiding this comment.
Preserve casing of grandfathered sign-language tags
For the accepted grandfathered tags sgn-BE-FR, sgn-BE-NL, and sgn-CH-DE, this records only the first two-letter component as a region, causing str() to return forms such as sgn-BE-fr. These tags are fixed grandfathered spellings in RFC 5646's grammar, and the previous formatter preserved both uppercase components, so grandfathered tags need dedicated display casing rather than the normal structural inference.
Useful? React with 👍 / 👎.
No description provided.