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