Skip to content

Commit 888e5b4

Browse files
committed
filtering surrogate code point per css3-syntax
1 parent 28bb7b0 commit 888e5b4

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

org/w3c/css/util/UnescapeFilterReader.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,23 @@ public int read()
1616
int esc;
1717
int c = in.read();
1818
// https://www.w3.org/TR/css-syntax-3/#input-preprocessing
19-
if (c == 13) { // U+000D CARRIAGE RETURN (CR)
19+
if (c == 0x000d) { // U+000D CARRIAGE RETURN (CR)
2020
mark(1);
2121
c = in.read();
2222
// eat any LF
23-
if (c != 10) { // U+000A LINE FEED (LF)
23+
if (c != 0x000a) { // U+000A LINE FEED (LF)
2424
reset();
2525
}
26-
return 10; // U+000A LINE FEED (LF)
26+
return 0x000a; // U+000A LINE FEED (LF)
2727
}
28-
if (c == 12) { //U+000C FORM FEED (FF)
29-
return 10;// U+000A LINE FEED (LF)
28+
if (c == 0x000c) { //U+000C FORM FEED (FF)
29+
return 0x000a;// U+000A LINE FEED (LF)
3030
}
3131
if (c == 0) { // U+0000 NULL
32-
return 65533; // U+FFFD REPLACEMENT CHARACTER
32+
return 0xffd; // U+FFFD REPLACEMENT CHARACTER
33+
}
34+
if (c >= 0xd800 && c <= 0xdfff) { // surrogate
35+
return 0xfffd;
3336
}
3437

3538
// now specific case of CSS unicode escape for ascii values [A-Za-z0-9].
@@ -94,16 +97,18 @@ public int read(char[] cbuf, int off, int len) throws IOException {
9497
}
9598
for (i = 0, j = 0; i < l; i++) {
9699
// pre-processing
97-
if (chars[i] == 13) {
98-
chars[j++] = 10;
100+
if (chars[i] == 0x000d) {
101+
chars[j++] = 0x000a;
99102
// test for CRLF
100-
if (i + 1 < l && chars[i + 1] == 10) {
103+
if (i + 1 < l && chars[i + 1] == 0x000a) {
101104
i++;
102105
}
103-
} else if (chars[i] == 12) {
104-
chars[j++] = 10;
106+
} else if (chars[i] == 0x000c) {
107+
chars[j++] = 0x000a;
105108
} else if (chars[i] == 0) {
106-
chars[j++] = 65533;
109+
chars[j++] = 0xfffd;
110+
} else if (chars[i] >= 0xd800 && chars[i] <= 0xdfff) {
111+
chars[j++] = 0xfffd;
107112
}
108113
// escaping
109114

0 commit comments

Comments
 (0)