Skip to content

Commit 3f1935c

Browse files
committed
Fix for w3c#229, with fix for unterminated rule set
1 parent ede9835 commit 3f1935c

File tree

1 file changed

+55
-6
lines changed

1 file changed

+55
-6
lines changed

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

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,8 @@ TOKEN :
566566
<DEFAULT>
567567
TOKEN :
568568
{
569-
< CDO : "<!--" >
569+
< SCO : "/*" >
570+
| < CDO : "<!--" >
570571
| < CDC : "-->" >
571572
| < INCLUDES : <TILDE> "=" >
572573
| < DASHMATCH : "|=" >
@@ -934,9 +935,18 @@ void afterImportDeclaration() :
934935
new ParseException(ac.getMsg().getString("parser.import_not_allowed"));
935936
addError(e, ret);
936937
} else {
937-
ParseException e =
938-
new ParseException(ac.getMsg().getString("generator.unrecognize"));
939-
addError(e, ret);
938+
// ignore unterminated comment
939+
CssVersion version = ac.getCssVersion();
940+
if (!ret.startsWith("/*") || (version.compareTo(CssVersion.CSS3) < 0)) {
941+
ParseException e = new ParseException(ac.getMsg().getString("generator.unrecognize"));
942+
addError(e, ret);
943+
} else {
944+
// read until the end
945+
Token t = getToken(0);
946+
while(t.kind != EOF) {
947+
t = getNextToken();
948+
}
949+
}
940950
}
941951
}
942952
) ignoreStatement() )*
@@ -2017,8 +2027,47 @@ void ruleSet() :
20172027
currentContext = null;
20182028
}
20192029
} catch (ParseException e) {
2020-
if ((ac.getCssProfile() != CssProfile.MOBILE) && !context_set.isEmpty()) {
2021-
addError(e, skipStatement());
2030+
if ((ac.getCssProfile() != CssProfile.MOBILE) && !context_set.isEmpty()) {
2031+
String ret = skipStatement();
2032+
CssVersion version = ac.getCssVersion();
2033+
Token t1 = getToken(1);
2034+
if (version.compareTo(CssVersion.CSS3) < 0) {
2035+
addError(e, ret);
2036+
} else if ((ret != null) && !ret.startsWith("/*") && (t1 != null && t1.kind == EOF)) {
2037+
addError(e, ret);
2038+
} else {
2039+
// unterminated comment, skip until EOF
2040+
Token t = getToken(0);
2041+
while(t.kind != EOF) {
2042+
t = getNextToken();
2043+
}
2044+
// then process
2045+
if (version.compareTo(CssVersion.CSS3) >= 0) {
2046+
markRule = true;
2047+
if (value_set != null) {
2048+
boolean first = true;
2049+
for (CssSelectors sel : context_set) {
2050+
if (first) {
2051+
handleRule(sel, value_set);
2052+
first = false;
2053+
} else {
2054+
// we need to duplicate properties in that case
2055+
// as property holds reference to the selectors and it interact
2056+
// badly with conflict detection
2057+
int vsize = value_set.size();
2058+
ArrayList<CssProperty> v = new ArrayList<CssProperty>(vsize);
2059+
for (CssProperty p : value_set) {
2060+
v.add(p.duplicate());
2061+
}
2062+
handleRule(sel, v);
2063+
}
2064+
}
2065+
setSelectorList(context_set);
2066+
endOfRule();
2067+
}
2068+
}
2069+
currentContext = null;
2070+
}
20222071
}
20232072
} catch (TokenMgrError e) {
20242073
addError(new ParseException(e.getMessage()), skipStatement());

0 commit comments

Comments
 (0)