From 0dca742f196bb91f70e7841b79b324256f6ff456 Mon Sep 17 00:00:00 2001 From: Norbert Garfield Date: Sat, 21 May 2022 11:52:30 +0000 Subject: [PATCH] Update UnicodeExtensionComponents Support both '-u-' and 'u-' extension patterns. --- boa_engine/src/builtins/intl/mod.rs | 5 ++++- boa_engine/src/builtins/intl/tests.rs | 7 +++++++ boa_engine/src/object/mod.rs | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/boa_engine/src/builtins/intl/mod.rs b/boa_engine/src/builtins/intl/mod.rs index 40f44a6999d..e87a3c59e30 100644 --- a/boa_engine/src/builtins/intl/mod.rs +++ b/boa_engine/src/builtins/intl/mod.rs @@ -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 { diff --git a/boa_engine/src/builtins/intl/tests.rs b/boa_engine/src/builtins/intl/tests.rs index f6310c23e59..b642feffe17 100644 --- a/boa_engine/src/builtins/intl/tests.rs +++ b/boa_engine/src/builtins/intl/tests.rs @@ -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] diff --git a/boa_engine/src/object/mod.rs b/boa_engine/src/object/mod.rs index 4eb089f64e4..5b8d0c44e13 100644 --- a/boa_engine/src/object/mod.rs +++ b/boa_engine/src/object/mod.rs @@ -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 {