| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <script src="../../js/resources/js-test-pre.js"></script> | 2 <script src="../../js/resources/js-test-pre.js"></script> |
| 3 <script> | 3 <script> |
| 4 | 4 |
| 5 description("Test invalid UTF-16 surrogate pairs with UTF-8 encoding"); | 5 description("Test invalid UTF-16 surrogate pairs with UTF-8 encoding"); |
| 6 | 6 |
| 7 var badStrings = [ | 7 var badStrings = [ |
| 8 { input: 'abc123', expected: 'abc123' }, // Sanity check. | 8 { input: "'abc123'", expected: [97, 98, 99, 49, 50, 51] }, // Sanity check. |
| 9 { input: '\ud800', expected: '\ufffd' }, // Surrogate half. | 9 { input: "'\\ud800'", expected: [0xef, 0xbf, 0xbd] }, // Surrogate half. |
| 10 { input: '\udc00', expected: '\ufffd' }, // Surrogate half. | 10 { input: "'\\udc00'", expected: [0xef, 0xbf, 0xbd] }, // Surrogate half. |
| 11 { input: 'abc\ud800def', expected: 'abc\ufffddef' }, // Surrogate half. | 11 { input: "'abc\\ud800123'", expected: [0x61, 0x62, 0x63, 0xef, 0xbf, 0xbd, 0
x31, 0x32, 0x33] }, // Surrogate half. |
| 12 { input: 'abc\udc00def', expected: 'abc\ufffddef' }, // Surrogate half. | 12 { input: "'abc\\udc00123'", expected: [0x61, 0x62, 0x63, 0xef, 0xbf, 0xbd, 0
x31, 0x32, 0x33] }, // Surrogate half. |
| 13 { input: '\udc00\ud800', expected: '\ufffd\ufffd' } // Wrong order. | 13 { input: "'\\udc00\\ud800'", expected: [239, 191, 189, 239, 191, 189] } //
Wrong order. |
| 14 ]; | 14 ]; |
| 15 | 15 |
| 16 badStrings.forEach( | 16 badStrings.forEach( |
| 17 function(t) { | 17 function(t) { |
| 18 evalAndLog("encoded = new TextEncoder('utf-8').encode(" + JSON.stringify
(t.input) + ")"); | 18 evalAndLog("encoded = new TextEncoder('utf-8').encode(" + t.input + ")")
; |
| 19 evalAndLog("decoded = new TextDecoder('utf-8').decode(encoded)"); | 19 shouldBeEqualToString("JSON.stringify([].slice.call(encoded))", JSON.str
ingify(t.expected)); |
| 20 shouldBeEqualToString("decoded", t.expected); | |
| 21 debug(""); | 20 debug(""); |
| 22 }); | 21 }); |
| 23 | 22 |
| 24 </script> | 23 </script> |
| 25 <script src="../../js/resources/js-test-post.js"></script> | 24 <script src="../../js/resources/js-test-post.js"></script> |
| OLD | NEW |