Skip to content

Commit

Permalink
Update UnicodeExtensionComponents
Browse files Browse the repository at this point in the history
Support both '-u-' and 'u-' extension patterns.
  • Loading branch information
NorbertGarfield committed May 30, 2022
1 parent 43964cf commit 0dca742
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion boa_engine/src/builtins/intl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,10 @@ fn unicode_extension_components(extension: &JsString) -> UniExtRecord {
let size = extension.len();

// 5. Let k be 3.
let mut k = 3;
//
// Actually, it has to be 3 when the extension begins with dash (-u-ca-gregory).
// When the extension begins with u (u-ca-gregory), start with 2.
let mut k = if extension.starts_with("u-") { 2 } else { 3 };

// 6. Repeat, while k < size,
while k < size {
Expand Down
7 changes: 7 additions & 0 deletions boa_engine/src/builtins/intl/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ fn uni_ext_comp() {
assert_eq!(components.keywords.len(), 1);
assert_eq!(components.keywords[0].key, "ca");
assert_eq!(components.keywords[0].value, "islamic-civil");

let ext = JsString::new("u-ca-islamic-civil");
let components = unicode_extension_components(&ext);
assert!(components.attributes.is_empty());
assert_eq!(components.keywords.len(), 1);
assert_eq!(components.keywords[0].key, "ca");
assert_eq!(components.keywords[0].value, "islamic-civil");
}

#[test]
Expand Down
1 change: 1 addition & 0 deletions boa_engine/src/object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,7 @@ impl Object {
}
}

#[cfg(feature = "intl")]
#[inline]
pub fn as_date_time_format_mut(&mut self) -> Option<&mut DateTimeFormat> {
match self.data {
Expand Down

0 comments on commit 0dca742

Please sign in to comment.