Skip to content

tighten language tag parsing - #11

Merged
nepinhum merged 3 commits into
masterfrom
fix/language-tag-subset
Oct 8, 2026
Merged

nepinhum merged 3 commits into
masterfrom
fix/language-tag-subset

Conversation

@nepinhum

@nepinhum nepinhum commented Oct 8, 2026

Copy link
Copy Markdown
Owner

No description provided.

@nepinhum

nepinhum commented Oct 8, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-08T15:39:22.665204Z 48ceb5c Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread language.v
Comment on lines +195 to +196
if !is_variant_subtag(part) {
return error('language tag has an invalid subtag')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment thread language.v Outdated
Comment on lines +164 to +165
if index > 0 && part.len == 4 && is_language_subtag_alpha(part) {
return part[0..1].to_upper() + part[1..].to_lower()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@nepinhum

nepinhum commented Oct 8, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread language.v Outdated
Comment on lines +72 to +73
return LanguageTag{
parts: tag.parts[..private_index].clone()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment thread language.v
Comment on lines +214 to +215
if !is_variant_subtag(part) {
return error('language tag has an invalid subtag')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@nepinhum

nepinhum commented Oct 8, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@nepinhum
nepinhum merged commit 694ff2d into master Oct 8, 2026
1 check passed
@nepinhum
nepinhum deleted the fix/language-tag-subset branch October 8, 2026 15:38

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread language.v
Comment on lines +195 to +196
mut index := 1
if index < parts.len && is_script_subtag(parts[index]) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment thread language.v
Comment on lines +191 to +192
if !is_language_subtag_alpha(parts[0]) || parts[0].len < 2 || parts[0].len > 8 {
return error('language tag has an invalid language subtag')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment thread language.v
Comment on lines +168 to +170
if index < parts.len && is_region_subtag(parts[index]) {
region_index = index
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant