Skip to content

Commit 5ce81d7

Browse files
committed
always read more to ensure we are not stuck when asked to read 1 char and end up with an unescaped escape
1 parent 888e5b4 commit 5ce81d7

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

org/w3c/css/util/UnescapeFilterReader.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,14 @@ public int read(char[] cbuf, int off, int len) throws IOException {
8989
int i, j, k, l, cki;
9090
boolean ignoreEscape = false;
9191

92-
char[] chars = new char[len];
93-
in.mark(len);
94-
l = super.read(chars, 0, len);
92+
char[] chars = new char[len + 8];
93+
in.mark(len + 8);
94+
l = super.read(chars, 0, len + 8);
95+
9596
if (l <= 0) {
9697
return l;
9798
}
98-
for (i = 0, j = 0; i < l; i++) {
99+
for (i = 0, j = 0; i < l && j < len; i++) {
99100
// pre-processing
100101
if (chars[i] == 0x000d) {
101102
chars[j++] = 0x000a;
@@ -196,6 +197,11 @@ public int read(char[] cbuf, int off, int len) throws IOException {
196197
}
197198

198199
System.arraycopy(chars, 0, cbuf, off, j);
200+
// as we read more to read a past escaped character, we must "unread" those.
201+
if (i < l) {
202+
in.reset();
203+
in.skip(i);
204+
}
199205
return j;
200206
}
201207
}

0 commit comments

Comments
 (0)