Skip to content

Normalize and validate host locales - #473

Merged
lukewilliamboswell merged 1 commit into
mainfrom
fix/issue-439-normalize-locales
Aug 14, 2026
Merged

Normalize and validate host locales#473
lukewilliamboswell merged 1 commit into
mainfrom
fix/issue-439-normalize-locales

Conversation

@lukewilliamboswell

Copy link
Copy Markdown
Collaborator

Closes #439.

Root cause

The locale host functions forwarded OS strings without validating the public Locale invariant. They also replaced discovery failures with an invented en-US, making NotAvailable unreachable.

Fix

  • normalize POSIX locale forms by trimming whitespace, stripping .encoding and @modifier suffixes, and replacing underscores with hyphens
  • treat C and POSIX as non-language locales and omit them
  • validate normalized values against the same pragmatic BCP 47 structure enforced by Locale.parse
  • remove invalid values and case-insensitive duplicates while preserving preference order
  • return NotAvailable when no valid preferred locale remains instead of inventing en-US
  • document the normalization, rejection, and deduplication behavior
  • add platform-independent tests covering representative Linux/POSIX, macOS, and Windows inputs

Verification

  • cargo test --locked --lib (18 passed)
  • ./scripts/test.py --operation validate with pinned nightly 2026-08-13-2fdd90e (207 Roc tests and all example checks passed)
  • ./scripts/test.py --operation build --target x64musl --artifact-dir /tmp/basic-cli-439-artifacts
  • native locale example with controlled environments:
    • LANG=C -> NotAvailable, []
    • LANG=en_US.UTF-8 -> en-US, [en-US]
    • LANG=malformed! -> NotAvailable, []

A strict Clippy run was also attempted; it is currently blocked by pre-existing warnings in generated ABI glue and unrelated TCP/file code.

@lukewilliamboswell
lukewilliamboswell marked this pull request as ready for review August 14, 2026 03:03
@lukewilliamboswell
lukewilliamboswell merged commit 8458a9d into main Aug 14, 2026
25 checks passed
@lukewilliamboswell
lukewilliamboswell deleted the fix/issue-439-normalize-locales branch August 14, 2026 06:22
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.

Validate and normalize host locale values

1 participant