Skip to content

Commit 0467c2a

Browse files
committed
Remove the automatic canonicalisation of escapes, it is now forced only to remove padded escapes
like in gr\65 en -> gr\000065en to avoid the space (example is bad as it is modified as 'green') This fixes #130
1 parent d684f4c commit 0467c2a

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

org/w3c/css/parser/analyzer/CssParser.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8580,10 +8580,13 @@ final public boolean prio() throws ParseException {
85808580
String convertStringIndex(String s, int start, int len, boolean escapeFirst) throws ParseException {int index = start;
85818581
int t;
85828582
int maxCount = 0;
8583+
boolean gotWhiteSpace = false;
8584+
int count = 0;
85838585
if ((start == 0) && (len == s.length()) && (s.indexOf('\\') == -1)) {
85848586
return s;
85858587
}
85868588
StringBuilder buf = new StringBuilder(len);
8589+
maxCount = ((ac.getCssVersion() == CssVersion.CSS1) ? 4 : 6);
85878590

85888591
while (index < len) {
85898592
char c = s.charAt(index);
@@ -8596,11 +8599,7 @@ final public boolean prio() throws ParseException {
85968599
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
85978600
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
85988601
int numValue = Character.digit(c, 16);
8599-
int count = 1;
8600-
if (maxCount == 0) {
8601-
maxCount = ((ac.getCssVersion() == CssVersion.CSS1) ?
8602-
4 : 6);
8603-
}
8602+
count = 1;
86048603
while (index + 1 < len) {
86058604
c = s.charAt(index+1);
86068605
t = Character.digit(c, 16);
@@ -8612,8 +8611,10 @@ final public boolean prio() throws ParseException {
86128611
c == '\n' || c == '\f' ) {
86138612
// skip the latest white space
86148613
index++;
8614+
gotWhiteSpace = true;
86158615
} else if ( c == '\r' ) {
86168616
index++;
8617+
gotWhiteSpace = true;
86178618
// special case for \r\n
86188619
if (index+1 < len) {
86198620
if (s.charAt(index + 1) == '\n') {
@@ -8637,8 +8638,15 @@ final public boolean prio() throws ParseException {
86378638
buf.append((char) numValue);
86388639
break;
86398640
}
8640-
char b[] = new char[maxCount];
8641-
t = maxCount;
8641+
char b[];
8642+
// we fully escape when we have a space
8643+
if (gotWhiteSpace) {
8644+
b = new char[maxCount];
8645+
t = maxCount;
8646+
} else {
8647+
b = new char[count];
8648+
t = count;
8649+
}
86428650
while (t > 0) {
86438651
b[--t] = hexdigits[numValue & 0xF];
86448652
numValue >>>= 4;

org/w3c/css/parser/analyzer/CssParser.jj

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3949,10 +3949,13 @@ String convertStringIndex(String s, int start, int len, boolean escapeFirst) {
39493949
int index = start;
39503950
int t;
39513951
int maxCount = 0;
3952+
boolean gotWhiteSpace = false;
3953+
int count = 0;
39523954
if ((start == 0) && (len == s.length()) && (s.indexOf('\\') == -1)) {
39533955
return s;
39543956
}
39553957
StringBuilder buf = new StringBuilder(len);
3958+
maxCount = ((ac.getCssVersion() == CssVersion.CSS1) ? 4 : 6);
39563959

39573960
while (index < len) {
39583961
char c = s.charAt(index);
@@ -3965,11 +3968,7 @@ String convertStringIndex(String s, int start, int len, boolean escapeFirst) {
39653968
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
39663969
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
39673970
int numValue = Character.digit(c, 16);
3968-
int count = 1;
3969-
if (maxCount == 0) {
3970-
maxCount = ((ac.getCssVersion() == CssVersion.CSS1) ?
3971-
4 : 6);
3972-
}
3971+
count = 1;
39733972
while (index + 1 < len) {
39743973
c = s.charAt(index+1);
39753974
t = Character.digit(c, 16);
@@ -3981,8 +3980,10 @@ String convertStringIndex(String s, int start, int len, boolean escapeFirst) {
39813980
c == '\n' || c == '\f' ) {
39823981
// skip the latest white space
39833982
index++;
3983+
gotWhiteSpace = true;
39843984
} else if ( c == '\r' ) {
39853985
index++;
3986+
gotWhiteSpace = true;
39863987
// special case for \r\n
39873988
if (index+1 < len) {
39883989
if (s.charAt(index + 1) == '\n') {
@@ -4006,8 +4007,15 @@ String convertStringIndex(String s, int start, int len, boolean escapeFirst) {
40064007
buf.append((char) numValue);
40074008
break;
40084009
}
4009-
char b[] = new char[maxCount];
4010-
t = maxCount;
4010+
char b[];
4011+
// we fully escape when we have a space
4012+
if (gotWhiteSpace) {
4013+
b = new char[maxCount];
4014+
t = maxCount;
4015+
} else {
4016+
b = new char[count];
4017+
t = count;
4018+
}
40114019
while (t > 0) {
40124020
b[--t] = hexdigits[numValue & 0xF];
40134021
numValue >>>= 4;

0 commit comments

Comments
 (0)