Skip to content

Make preprocessing of input stream handle supplementary characters #385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions org/w3c/css/util/UnescapeFilterReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.FilterReader;
import java.io.IOException;
import java.io.Reader;
import java.lang.Character;

public class UnescapeFilterReader extends FilterReader {

Expand Down Expand Up @@ -32,7 +33,14 @@ public int read()
return 0xfffd; // U+FFFD REPLACEMENT CHARACTER
}
if (c >= 0xd800 && c <= 0xdfff) { // surrogate
return 0xfffd;
if (!Character.isHighSurrogate((char) c)) {
return 0xfffd;
}
mark(1);
if (!Character.isLowSurrogate((char) in.read())) {
return 0xfffd;
}
reset();
}

// now specific case of CSS unicode escape for ascii values [A-Za-z0-9].
Expand Down Expand Up @@ -109,7 +117,15 @@ public int read(char[] cbuf, int off, int len) throws IOException {
} else if (chars[i] == 0) {
chars[j++] = 0xfffd;
} else if (chars[i] >= 0xd800 && chars[i] <= 0xdfff) {
chars[j++] = 0xfffd;
if (i + 1 >= l) {
chars[j++] = 0xfffd;
} else if (!Character.isHighSurrogate((char) chars[i])) {
chars[j++] = 0xfffd;
} else if (!Character.isLowSurrogate((char) chars[i + 1])) {
chars[j++] = 0xfffd;
}
i++;
j++;
}
// escaping

Expand Down