validator icon indicating copy to clipboard operation
validator copied to clipboard

bcp47_strict_language_tag accepts repeated variant subtags forbidden by RFC5646

Open guocn opened this issue 1 month ago • 0 comments

The bcp47_strict_language_tag validator currently accepts repeated variant subtags, including the invalid example in RFC5646 section2.2.5:

v := validator.New()
fmt.Println(v.Var("de-DE-1901-1901", "bcp47_strict_language_tag")) // <nil>
fmt.Println(v.Var("sl-rozaj-biske-rozaj", "bcp47_strict_language_tag")) // <nil>
fmt.Println(v.Var("sl-ROZAJ-rozaj", "bcp47_strict_language_tag")) // <nil>

Expected: each fails validation. RFC5646 section2.2.5 item5 states “The same variant subtag MUST NOT be used more than once within a language tag” and explicitly identifies de-DE-1901-1901 as invalid: https://www.rfc-editor.org/rfc/rfc5646.html#section-2.2.5.

The current implementation validates each variant in isolation against the parser and registry but never checks whether an earlier variant in the same tag has already used it. The tag has already been lowercased, so case-insensitive duplicate tracking can stay local to that loop.

Reproduced on master a5843c6fbb596822bb41c4f12bdd5fec6420dc58, Go1.27.3/Linuxamd64. Five negative subtests fail on current source; five controls with distinct variants or repeated private-use subtags pass. This report concerns only duplicate variants; other BCP47 behavior and the non-strict validator are outside its scope. No security impact is claimed.

AI disclosure: OpenAI GPT-6.1 (cpa/gpt-6.1-sol) via OpenClaw performed source analysis, reproduction, patch/test generation and drafted this report. Outputs were locally verified; no human code review is claimed.

guocn avatar Oct 22 '26 11:10 guocn