OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <title>Encoding API: UTF-16 surrogate handling</title> |
| 3 <script src="../../../resources/testharness.js"></script> |
| 4 <script src="../../../resources/testharnessreport.js"></script> |
| 5 <script src="resources/shared.js"></script> |
| 6 <script> |
| 7 |
| 8 var bad = [ |
| 9 { |
| 10 encoding: 'utf-16le', |
| 11 input: [0x00, 0xd8], |
| 12 expected: '\uFFFD', |
| 13 name: 'lone surrogate lead' |
| 14 }, |
| 15 { |
| 16 encoding: 'utf-16le', |
| 17 input: [0x00, 0xdc], |
| 18 expected: '\uFFFD', |
| 19 name: 'lone surrogate trail' |
| 20 }, |
| 21 { |
| 22 encoding: 'utf-16le', |
| 23 input: [0x00, 0xd8, 0x00, 0x00], |
| 24 expected: '\uFFFD\u0000', |
| 25 name: 'unmatched surrogate lead' |
| 26 }, |
| 27 { |
| 28 encoding: 'utf-16le', |
| 29 input: [0x00, 0xdc, 0x00, 0x00], |
| 30 expected: '\uFFFD\u0000', |
| 31 name: 'unmatched surrogate trail' |
| 32 }, |
| 33 { |
| 34 encoding: 'utf-16le', |
| 35 input: [0x00, 0xdc, 0x00, 0xd8], |
| 36 expected: '\uFFFD\uFFFD', |
| 37 name: 'swapped surrogate pair' |
| 38 } |
| 39 ]; |
| 40 |
| 41 bad.forEach(function(t) { |
| 42 test(function() { |
| 43 assert_equals(new TextDecoder(t.encoding).decode(new Uint8Array(t.input)
), t.expected); |
| 44 }, t.encoding + " - " + t.name); |
| 45 test(function() { |
| 46 assert_throws({name: 'EncodingError'}, function() { |
| 47 new TextDecoder(t.encoding, {fatal: true}).decode(new Uint8Array(t.i
nput)) |
| 48 }); |
| 49 }, t.encoding + " - " + t.name + ' (fatal flag set)'); |
| 50 }); |
| 51 |
| 52 </script> |
OLD | NEW |