OLD | NEW |
---|---|
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <script src="../../../resources/js-test.js"></script> | 2 <title>Encoding API: Fatal flag</title> |
3 <script src="../../../resources/testharness.js"></script> | |
4 <script src="../../../resources/testharnessreport.js"></script> | |
5 <script src="resources/shared.js"></script> | |
3 <script> | 6 <script> |
4 | 7 |
5 description("Test the Encoding API's 'fatal' flag"); | |
6 | |
7 var bad = [ | 8 var bad = [ |
8 { encoding: 'utf-8', input: "[0xC0]" }, // ends early | 9 { encoding: 'utf-8', input: [0xFF], name: 'invalid code' }, |
9 { encoding: 'utf-8', input: "[0xC0, 0x00]" }, // invalid trail | 10 { encoding: 'utf-8', input: [0xC0], name: 'ends early' }, |
10 { encoding: 'utf-8', input: "[0xC0, 0xC0]" }, // invalid trail | 11 { encoding: 'utf-8', input: [0xC0, 0x00], name: 'invalid trail' }, |
11 { encoding: 'utf-8', input: "[0xE0]" }, // ends early | 12 { encoding: 'utf-8', input: [0xC0, 0xC0], name: 'invalid trail' }, |
12 { encoding: 'utf-8', input: "[0xE0, 0x00]" }, // invalid trail | 13 { encoding: 'utf-8', input: [0xE0], name: 'ends early' }, |
13 { encoding: 'utf-8', input: "[0xE0, 0xC0]" }, // invalid trail | 14 { encoding: 'utf-8', input: [0xE0, 0x00], name: 'invalid trail' }, |
14 { encoding: 'utf-8', input: "[0xE0, 0x80, 0x00]" }, // invalid trail | 15 { encoding: 'utf-8', input: [0xE0, 0xC0], name: 'invalid trail' }, |
15 { encoding: 'utf-8', input: "[0xE0, 0x80, 0xC0]" }, // invalid trail | 16 { encoding: 'utf-8', input: [0xE0, 0x80, 0x00], name: 'invalid trail' }, |
16 { encoding: 'utf-8', input: "[0xFC, 0x80, 0x80, 0x80, 0x80, 0x80]" }, // > 0 x10FFFF | 17 { encoding: 'utf-8', input: [0xE0, 0x80, 0xC0], name: 'invalid trail' }, |
jungshik at Google
2014/04/29 16:51:04
Please, add overlong sequences here.
<= U+007F r
jsbell
2014/04/29 21:41:18
Done.
| |
17 { encoding: 'utf-16le', input: "[0x00]" }, // truncated code unit | 18 { encoding: 'utf-8', input: [0xFC, 0x80, 0x80, 0x80, 0x80, 0x80], name: '> 0 x10FFFF' }, |
jungshik at Google
2014/04/29 16:51:04
Pls, also add a 6-byte sequence (valid in the orig
jsbell
2014/04/29 21:41:18
Done.
| |
18 { encoding: 'utf-16le', input: "[0x00, 0xd8]" }, // surrogate half | 19 { encoding: 'utf-16le', input: [0x00], name: 'truncated code unit' }, |
19 { encoding: 'utf-16le', input: "[0x00, 0xd8, 0x00, 0x00]" }, // surrogate ha lf | 20 { encoding: 'utf-16le', input: [0x00, 0xd8], name: 'surrogate half' }, |
20 { encoding: 'utf-16le', input: "[0x00, 0xdc, 0x00, 0x00]" }, // trail surrog ate | 21 { encoding: 'utf-16le', input: [0x00, 0xd8, 0x00, 0x00], name: 'surrogate ha lf' }, |
21 { encoding: 'utf-16le', input: "[0x00, 0xdc, 0x00, 0xd8]" } // swapped surr ogates | 22 { encoding: 'utf-16le', input: [0x00, 0xdc, 0x00, 0x00], name: 'trail surrog ate' }, |
23 { encoding: 'utf-16le', input: [0x00, 0xdc, 0x00, 0xd8], name: 'swapped surr ogates' } | |
22 // FIXME: Legacy encoding cases | 24 // FIXME: Legacy encoding cases |
23 ]; | 25 ]; |
24 | 26 |
25 bad.forEach(function(t) { | 27 bad.forEach(function(t) { |
26 shouldThrow("new TextDecoder('" + t.encoding + "', {fatal: true}).decode(new Uint8Array(" + t.input + "))"); | 28 test(function() { |
29 assert_throws({name: 'EncodingError'}, function() { | |
30 new TextDecoder(t.encoding, {fatal: true}).decode(new Uint8Array(t.i nput)) | |
31 }); | |
32 }, 'Fatal flag: ' + t.encoding + " - " + t.name); | |
27 }); | 33 }); |
28 | 34 |
29 </script> | 35 </script> |
OLD | NEW |