Skip to content

Commit

Permalink
Fix cmn-hans-cn-t-ca-u-ca-x_t-u (#6001)
Browse files Browse the repository at this point in the history
The issue here is that once the parser was in extensions mode, it would
only look at the first character of the `x_t` subtag (the produced
locale was `cmn-hans-cn-t-ca-u-ca-x-u`).

#5943 (comment)
  • Loading branch information
robertbastian authored Jan 15, 2025
1 parent 0959d99 commit 1bc501a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
15 changes: 10 additions & 5 deletions components/locale_core/src/extensions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,26 +264,31 @@ impl Extensions {
if subtag.is_empty() {
return Err(ParseError::InvalidExtension);
}
match subtag.first().map(|b| ExtensionType::try_from_byte(*b)) {
Some(Ok(ExtensionType::Unicode)) => {

let &[subtag] = subtag else {
return Err(ParseError::InvalidExtension);
};

match ExtensionType::try_from_byte(subtag) {
Ok(ExtensionType::Unicode) => {
if unicode.is_some() {
return Err(ParseError::DuplicatedExtension);
}
unicode = Some(Unicode::try_from_iter(iter)?);
}
Some(Ok(ExtensionType::Transform)) => {
Ok(ExtensionType::Transform) => {
if transform.is_some() {
return Err(ParseError::DuplicatedExtension);
}
transform = Some(Transform::try_from_iter(iter)?);
}
Some(Ok(ExtensionType::Private)) => {
Ok(ExtensionType::Private) => {
if private.is_some() {
return Err(ParseError::DuplicatedExtension);
}
private = Some(Private::try_from_iter(iter)?);
}
Some(Ok(ExtensionType::Other(ext))) => {
Ok(ExtensionType::Other(ext)) => {
if other.iter().any(|o: &Other| o.get_ext_byte() == ext) {
return Err(ParseError::DuplicatedExtension);
}
Expand Down
10 changes: 10 additions & 0 deletions components/locale_core/tests/fixtures/invalid-extensions.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
[
{
"input": {
"type": "Locale",
"identifier": "cmn-hans-cn-t-ca-u-ca-x_t-u"
},
"output": {
"error": "InvalidExtension",
"text": "unused"
}
},
{
"input": {
"type": "Locale",
Expand Down
2 changes: 1 addition & 1 deletion components/locale_core/tests/locale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn test_locale_parsing() {
}

#[test]
fn test_langid_invalid() {
fn test_locale_invalid() {
let data = serde_json::from_str(include_str!("fixtures/invalid-extensions.json"))
.expect("Failed to read a fixture");

Expand Down

0 comments on commit 1bc501a

Please sign in to comment.