| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <title>Encoding API: Invalid UTF-16 surrogates with UTF-8 encoding</title> | |
| 3 <script src="../../../resources/testharness.js"></script> | |
| 4 <script src="../../../resources/testharnessreport.js"></script> | |
| 5 <script> | |
| 6 | |
| 7 var badStrings = [ | |
| 8 { | |
| 9 input: 'abc123', | |
| 10 expected: [0x61, 0x62, 0x63, 0x31, 0x32, 0x33], | |
| 11 decoded: 'abc123', | |
| 12 name: 'Sanity check' | |
| 13 }, | |
| 14 { | |
| 15 input: '\uD800', | |
| 16 expected: [0xef, 0xbf, 0xbd], | |
| 17 decoded: '\uFFFD', | |
| 18 name: 'Surrogate half (low)' | |
| 19 }, | |
| 20 { | |
| 21 input: '\uDC00', | |
| 22 expected: [0xef, 0xbf, 0xbd], | |
| 23 decoded: '\uFFFD', | |
| 24 name: 'Surrogate half (high)' | |
| 25 }, | |
| 26 { | |
| 27 input: 'abc\uD800123', | |
| 28 expected: [0x61, 0x62, 0x63, 0xef, 0xbf, 0xbd, 0x31, 0x32, 0x33], | |
| 29 decoded: 'abc\uFFFD123', | |
| 30 name: 'Surrogate half (low), in a string' | |
| 31 }, | |
| 32 { | |
| 33 input: 'abc\uDC00123', | |
| 34 expected: [0x61, 0x62, 0x63, 0xef, 0xbf, 0xbd, 0x31, 0x32, 0x33], | |
| 35 decoded: 'abc\uFFFD123', | |
| 36 name: 'Surrogate half (high), in a string' | |
| 37 }, | |
| 38 { | |
| 39 input: '\uDC00\uD800', | |
| 40 expected: [0xef, 0xbf, 0xbd, 0xef, 0xbf, 0xbd], | |
| 41 decoded: '\uFFFD\uFFFD', | |
| 42 name: 'Wrong order' | |
| 43 } | |
| 44 ]; | |
| 45 | |
| 46 badStrings.forEach(function(t) { | |
| 47 test(function() { | |
| 48 var encoded = new TextEncoder('utf-8').encode(t.input); | |
| 49 assert_array_equals([].slice.call(encoded), t.expected); | |
| 50 assert_equals(new TextDecoder('utf-8').decode(encoded), t.decoded); | |
| 51 }, 'Invalid surrogates encoded into UTF-8: ' + t.name); | |
| 52 }); | |
| 53 | |
| 54 </script> | |
| OLD | NEW |