Visitar URL original
fix(isLocale): match private-use and grandfathered tags case-insensitively by FanWu-ai · Pull Request #2905 · validatorjs/validator.js · GitHub
Skip to content

fix(isLocale): match private-use and grandfathered tags case-insensitively - #2905

Open
FanWu-ai wants to merge 1 commit into
validatorjs:masterfrom
FanWu-ai:fix/locale-case-insensitive-20261006
Open

FanWu-ai wants to merge 1 commit into
validatorjs:masterfrom
FanWu-ai:fix/locale-case-insensitive-20261006

Conversation

@FanWu-ai

@FanWu-ai FanWu-ai commented Oct 6, 2026

Copy link
Copy Markdown

isLocale('X-WHATEVER'), isLocale('de-CH-X-phonebk'), and isLocale('I-AMI') currently return false, although their lowercase equivalents pass. The assembled regex uses case-flexible character classes for most subtags but matches the literal private-use prefix and grandfathered tags case-sensitively.

Compile the language-tag regex with the case-insensitive flag. Add regression coverage for mixed-case private-use prefixes, grandfathered tags, and malformed controls. This preserves the existing accepted syntax and underscore compatibility.

RFC 5646 §2.1.1 requires case-insensitive treatment of language tags and explicitly gives I-AMI as equivalent to i-ami: https://www.rfc-editor.org/rfc/rfc5646.html#section-2.1.1

Validation: the regression fails against the original source. npm test passes all builds, lint and 324 tests with 100% statement/function/line coverage; branch coverage remains 96.59%. Generated Node/browser/minified-browser checks also pass. Node 24.19.0 on Linux; the CI version matrix has not been run locally.

Prepared with OpenAI Codex assistance.

Checklist

  • PR contains only related changes
  • README unchanged: existing contract is restored
  • Regression tests added
  • Primary reference provided

@FanWu-ai
FanWu-ai marked this pull request as ready for review October 6, 2026 04:17
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