OLD | NEW |
---|---|
(Empty) | |
1 <!DOCTYPE html> | |
2 <title>Encoding API: TextDecoder ignoreBOM option</title> | |
3 <script src="../../../resources/testharness.js"></script> | |
4 <script src="../../../resources/testharnessreport.js"></script> | |
5 <script> | |
6 | |
7 test(function() { | |
8 | |
9 var cases = [ | |
10 {encoding: 'utf-8', bytes: [0xEF, 0xBB, 0xBF, 0x61, 0x62, 0x63]}, | |
11 {encoding: 'utf-16le', bytes: [0xFF, 0xFE, 0x61, 0x00, 0x62, 0x00, 0x63, 0x00]}, | |
12 {encoding: 'utf-16be', bytes: [0xFE, 0xFF, 0x00, 0x61, 0x00, 0x62, 0x00, 0x63]} | |
13 ]; | |
14 | |
15 var BOM = '\uFEFF'; | |
16 | |
17 cases.forEach(function(testCase) { | |
18 var decoder = new TextDecoder(testCase.encoding, {ignoreBOM: true}); | |
19 assert_equals( | |
20 decoder.decode(new Uint8Array(testCase.bytes)), | |
21 BOM + 'abc', | |
22 testCase.encoding + ': BOM should be present in decoded string if ig nored'); | |
23 | |
24 decoder = new TextDecoder(testCase.encoding, {ignoreBOM: false}); | |
25 assert_equals( | |
26 decoder.decode(new Uint8Array(testCase.bytes)), | |
27 'abc', | |
28 testCase.encoding + ': BOM should be absent from decoded string if n ot ignored'); | |
29 | |
30 decoder = new TextDecoder(testCase.encoding); | |
31 assert_equals( | |
32 decoder.decode(new Uint8Array(testCase.bytes)), | |
33 'abc', | |
34 testCase.encoding + ': Default is to ignore the BOM'); | |
jungshik at Google
2014/05/27 17:09:11
Default is to "eat" the BOM (no BOM in the decoded
jsbell
2014/05/27 17:40:46
Yes.
| |
35 }); | |
36 | |
37 }, "BOM is ignored if ignoreBOM option is specified"); | |
38 </script> | |
OLD | NEW |