OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <title>Encoding API: ScalarValueString surrogate handling when encoding</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 input: '\uD800', |
| 11 expected: '\uFFFD', |
| 12 name: 'lone surrogate lead' |
| 13 }, |
| 14 { |
| 15 input: '\uDC00', |
| 16 expected: '\uFFFD', |
| 17 name: 'lone surrogate trail' |
| 18 }, |
| 19 { |
| 20 input: '\uD800\u0000', |
| 21 expected: '\uFFFD\u0000', |
| 22 name: 'unmatched surrogate lead' |
| 23 }, |
| 24 { |
| 25 input: '\uDC00\u0000', |
| 26 expected: '\uFFFD\u0000', |
| 27 name: 'unmatched surrogate trail' |
| 28 }, |
| 29 { |
| 30 input: '\uDC00\uD800', |
| 31 expected: '\uFFFD\uFFFD', |
| 32 name: 'swapped surrogate pair' |
| 33 }, |
| 34 { |
| 35 input: '\uD834\uDD1E', |
| 36 expected: '\uD834\uDD1E', |
| 37 name: 'properly encoded MUSICAL SYMBOL G CLEF (U+1D11E)' |
| 38 } |
| 39 ]; |
| 40 |
| 41 var encoding = 'utf-8'; |
| 42 |
| 43 bad.forEach(function(t) { |
| 44 test(function() { |
| 45 var encoded = new TextEncoder(encoding).encode(t.input); |
| 46 var decoded = new TextDecoder(encoding).decode(encoded); |
| 47 assert_equals(decoded, t.expected); |
| 48 }, 'ScalarValueString handling: ' + t.name); |
| 49 }); |
| 50 |
| 51 test(function() { |
| 52 assert_equals(new TextEncoder(encoding).encode().length, 0, 'Should default
to empty string'); |
| 53 }, 'ScalarValueString default'); |
| 54 |
| 55 </script> |
OLD | NEW |