invalidutf8.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. // !!!! DO NOT EDIT THIS FILE WITH A NORMAL TEXT EDITOR !!!
  6. // This file contains invalid UTF8 sequences that any sane editor would "fix".
  7. // but would, however break this test. If you do edit it then make sure the invalid
  8. // sequences are retained in the edited file before checking in.
  9. function write(a) {
  10. if (this.WScript == undefined) {
  11. document.write(a);
  12. document.write("</br>");
  13. }
  14. else
  15. WScript.Echo(a)
  16. }
  17. function test(a, b) {
  18. write(a == b);
  19. var evalText = "result = \"" + a + "\"";
  20. eval(evalText);
  21. write(a == result);
  22. }
  23. // String containing invalid sequence C0 20 should be equivient to \uFFFD\u00020"
  24. var C020 = "À ";
  25. var Rep20 = "\uFFFD\u0020";
  26. test(C020, Rep20);
  27. // Ensure a valid sequence gets translated correctly.
  28. var C885 = "È…";
  29. var x0205 = "\u0205";
  30. test(C885, x0205);
  31. // Ensure surrogate pairs are encoded correctly
  32. var F0909080 = "�";
  33. var D801DC00 = "\uD801\uDC00";
  34. test(F0909080, D801DC00);
  35. // Ensure invalid surrogate pairs are replaced with replacement characters.
  36. var EDA081_EDB080 = "�";
  37. var Repx6 = "\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD";
  38. test(EDA081_EDB080, Repx6);
  39. // Ensure invalid characters are not replaced with replacement characters.
  40. var EFBFBF = "ï¿¿";
  41. var Repx7 = "\uFFFF";
  42. test(EFBFBF, Repx7);