Skip to content

Fix private-use singleton without a subtag being accepted - #25

Open
spokodev wants to merge 1 commit into
wooorm:mainfrom
spokodev:fix/hunt
Open

Fix private-use singleton without a subtag being accepted#25
spokodev wants to merge 1 commit into
wooorm:mainfrom
spokodev:fix/hunt

Conversation

@spokodev

@spokodev spokodev commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

A trailing private-use singleton with no subtags is silently accepted and dropped.

import {parse, stringify} from 'bcp-47'

const schema = parse('en-x')
// { language: 'en', privateuse: [], ... } — no warning
stringify(schema) // 'en'  (the `-x` is lost, round-trip broken)

Per RFC 5646, privateuse = "x" 1*("-" (1*8alphanum)), so x must be followed by at least one subtag. The dangling-extension-singleton equivalent (en-i) is already rejected with "Found superfluous content after tag", but the private-use branch is not.

The entry check only verifies the x singleton is present, not that a subtag follows, so the -x is consumed and index advances to the end, leaving no superfluous content to report. Fix: require - + an alphanumeric after x before entering the private-use section, mirroring the extension entry guard. en-x now falls through to the existing superfluous-content check, matching en-i.

Adds a regression test. Valid tags (x-whatever, en-x-a, az-Arab-x-AZE-derbend, …) are unaffected; all existing tests and fixtures pass.

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