@@ -288,6 +288,66 @@ fn decoder_bom_ignore_bom_false(encoding: &'static str, bytes: &'static [u8]) {
288288 ) ;
289289}
290290
291+ #[ test_case( "UTF-8" , "utf-8" ; "uppercase utf8" ) ]
292+ #[ test_case( " utf-8 " , "utf-8" ; "spaced utf8" ) ]
293+ #[ test_case( "\n utf-16\t " , "utf-16le" ; "spaced utf16" ) ]
294+ #[ test_case( "UTF-16BE" , "utf-16be" ; "uppercase utf16be" ) ]
295+ #[ test_case( "utf8" , "utf-8" ; "utf8 alias" ) ]
296+ #[ test_case( "Unicode-1-1-UTF-8" , "utf-8" ; "unicode alias" ) ]
297+ #[ test_case( "csUnicode" , "utf-16le" ; "csunicode alias" ) ]
298+ #[ test_case( " unicodefeff " , "utf-16le" ; "unicodefeff alias" ) ]
299+ #[ test_case( "UnicodeFFFE" , "utf-16be" ; "unicodefffe alias" ) ]
300+ fn decoder_normalizes_supported_labels ( label : & ' static str , expected : & ' static str ) {
301+ let context = & mut Context :: default ( ) ;
302+ text:: register ( None , context) . unwrap ( ) ;
303+
304+ run_test_actions_with (
305+ [
306+ TestAction :: run ( format ! (
307+ r#"
308+ const d = new TextDecoder({label:?});
309+ encoding = d.encoding;
310+ "#
311+ ) ) ,
312+ TestAction :: inspect_context ( move |context| {
313+ let encoding = context
314+ . global_object ( )
315+ . get ( js_str ! ( "encoding" ) , context)
316+ . unwrap ( ) ;
317+ assert_eq ! ( encoding. as_string( ) , Some ( JsString :: from( expected) ) ) ;
318+ } ) ,
319+ ] ,
320+ context,
321+ ) ;
322+ }
323+
324+ #[ test]
325+ fn decoder_rejects_unsupported_label_after_normalization ( ) {
326+ let context = & mut Context :: default ( ) ;
327+ text:: register ( None , context) . unwrap ( ) ;
328+
329+ run_test_actions_with (
330+ [
331+ TestAction :: run ( indoc ! { r#"
332+ threw = false;
333+ try {
334+ new TextDecoder(" utf-32 ");
335+ } catch (e) {
336+ threw = e instanceof RangeError;
337+ }
338+ "# } ) ,
339+ TestAction :: inspect_context ( |context| {
340+ let threw = context
341+ . global_object ( )
342+ . get ( js_str ! ( "threw" ) , context)
343+ . unwrap ( ) ;
344+ assert_eq ! ( threw. as_boolean( ) , Some ( true ) ) ;
345+ } ) ,
346+ ] ,
347+ context,
348+ ) ;
349+ }
350+
291351#[ test]
292352fn decoder_ignore_bom_getter ( ) {
293353 let context = & mut Context :: default ( ) ;
0 commit comments