Skip to content

Commit a845fbb

Browse files
Report bad prop in declaration w/ vendor/hack flag
This change causes errors to be reported for bad property names even in cases where the declaration containing the property has an expression with values that have been flagged as vendor extensions or CSS hacks. Without this change, if an expression is flagged as containing a value that is a vendor extension or CSS hack but the declaration it’s in has an invalid property name (e.g., `background-image` misspelled as `backround-image` but with a value of `-webkit-image-set(...)`), no error is emitted for the invalid property name. This change works by 1) removing from the createProperty method in the CssPropertyFactory code the warning-report handling for declarations that have vendor extensions and CSS hacks, 2) moving that handling into the parser code, where it now checks what method threw an InvalidParamException if one is thrown when parsing a declaration, and 3) reporting an error if the method that threw InvalidParamException in a vendor-extension/CSS-hack case is the createProperty method (which means it was thrown for a bad property name) rather than other code that throws it (which indicates that it’s a vendor-extension/CSS-hack *value* rather than a bad property name). (Incidentally, a potential alternative way of dealing with this problem would be to not throw an InvalidParamException for bad property names in the createProperty method to begin with, but to instead throw some different (new?) exception that could be caught and handled separately.) Note that this change also adds handling to emit a specific warning or error in the case where a function name is a vendor extension (that is, the function name starts with `-`) — because after the rest of this change is made to the code, no error or warning would otherwise be reported in that case.
1 parent 50bad57 commit a845fbb

File tree

3 files changed

+155
-133
lines changed

3 files changed

+155
-133
lines changed

org/w3c/css/parser/CssPropertyFactory.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,8 @@ public synchronized CssProperty createProperty(ApplContext ac, AtRule atRule, St
178178
if (isVendorExtension(property)) {
179179
throw new WarningParamException("vendor-extension", property);
180180
}
181-
if (expression.hasVendorExtensions()) {
182-
throw new WarningParamException("vendor-extension", expression.toStringFromStart());
183-
}
184181
}
185182

186-
if (ac.getTreatCssHacksAsWarnings()) {
187-
if (expression.hasCssHack()) {
188-
throw new WarningParamException("css-hack", expression.toStringFromStart());
189-
}
190-
}
191183
try {
192184
atRuleMedia = (AtRuleMedia) atRule;
193185
// TODO FIXME in fact, it should use a vector of media instead of extracting

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

Lines changed: 139 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -4137,7 +4137,14 @@ final public ArrayList<CssProperty> declarations() throws ParseException {if(!va
41374137
warningException.getMessageArgs());
41384138
} else {
41394139
values.starts();
4140-
addError(e, (CssExpression) values);
4140+
if (values.hasCssHack() || values.hasVendorExtensions()) {
4141+
if ("createProperty"
4142+
.equals(e.getStackTrace()[0].getMethodName())) {
4143+
addError(e, (CssExpression) values);
4144+
}
4145+
} else {
4146+
addError(e, (CssExpression) values);
4147+
}
41414148
}
41424149
}
41434150
{if ("" != null) return null;}
@@ -5402,6 +5409,14 @@ final public boolean prio() throws ParseException {
54025409
f.set(n.image.substring(0, n.image.length() - 1), exp);
54035410
if (funcname.charAt(0) == '-') {
54045411
exp.markVendorExtension();
5412+
if (ac.getTreatVendorExtensionsAsWarnings()) {
5413+
ac.getFrame().addWarning("vendor-extension",
5414+
funcname.substring(0, funcname.length() - 1));
5415+
} else {
5416+
addError(new ParseException(ac.getMsg()
5417+
.getString("warning.vendor-extension")),
5418+
funcname);
5419+
}
54055420
}
54065421
{if ("" != null) return f;}
54075422
}
@@ -5743,43 +5758,12 @@ private boolean jj_2_5(int xla)
57435758
finally { jj_save(4, xla); }
57445759
}
57455760

5746-
private boolean jj_3R_175()
5747-
{
5748-
if (jj_scan_token(STRING)) return true;
5749-
return false;
5750-
}
5751-
57525761
private boolean jj_3R_154()
57535762
{
57545763
if (jj_scan_token(PLUS)) return true;
57555764
return false;
57565765
}
57575766

5758-
private boolean jj_3R_174()
5759-
{
5760-
if (jj_3R_183()) return true;
5761-
return false;
5762-
}
5763-
5764-
private boolean jj_3_5()
5765-
{
5766-
if (jj_3R_127()) return true;
5767-
if (jj_scan_token(LPARAN)) return true;
5768-
return false;
5769-
}
5770-
5771-
private boolean jj_3R_173()
5772-
{
5773-
if (jj_3R_152()) return true;
5774-
return false;
5775-
}
5776-
5777-
private boolean jj_3R_172()
5778-
{
5779-
if (jj_3R_151()) return true;
5780-
return false;
5781-
}
5782-
57835767
private boolean jj_3R_153()
57845768
{
57855769
if (jj_scan_token(MINUS)) return true;
@@ -5797,47 +5781,6 @@ private boolean jj_3R_137()
57975781
return false;
57985782
}
57995783

5800-
private boolean jj_3R_187()
5801-
{
5802-
if (jj_3R_129()) return true;
5803-
return false;
5804-
}
5805-
5806-
private boolean jj_3R_139()
5807-
{
5808-
Token xsp;
5809-
xsp = jj_scanpos;
5810-
if (jj_3R_172()) {
5811-
jj_scanpos = xsp;
5812-
if (jj_3R_173()) {
5813-
jj_scanpos = xsp;
5814-
if (jj_3R_174()) {
5815-
jj_scanpos = xsp;
5816-
if (jj_3R_175()) {
5817-
jj_scanpos = xsp;
5818-
if (jj_3R_176()) {
5819-
jj_scanpos = xsp;
5820-
if (jj_3R_177()) {
5821-
jj_scanpos = xsp;
5822-
if (jj_3R_178()) {
5823-
jj_scanpos = xsp;
5824-
if (jj_3R_179()) {
5825-
jj_scanpos = xsp;
5826-
if (jj_3R_180()) {
5827-
jj_scanpos = xsp;
5828-
if (jj_3R_181()) return true;
5829-
}
5830-
}
5831-
}
5832-
}
5833-
}
5834-
}
5835-
}
5836-
}
5837-
}
5838-
return false;
5839-
}
5840-
58415784
private boolean jj_3R_171()
58425785
{
58435786
if (jj_scan_token(DIMEN_9)) return true;
@@ -5888,26 +5831,12 @@ private boolean jj_3R_169()
58885831
return false;
58895832
}
58905833

5891-
private boolean jj_3R_182()
5892-
{
5893-
if (jj_scan_token(COMMA)) return true;
5894-
return false;
5895-
}
5896-
58975834
private boolean jj_3R_185()
58985835
{
58995836
if (jj_3R_187()) return true;
59005837
return false;
59015838
}
59025839

5903-
private boolean jj_3R_140()
5904-
{
5905-
Token xsp;
5906-
xsp = jj_scanpos;
5907-
if (jj_3R_182()) jj_scanpos = xsp;
5908-
return false;
5909-
}
5910-
59115840
private boolean jj_3R_168()
59125841
{
59135842
if (jj_scan_token(DIMEN)) return true;
@@ -5938,6 +5867,23 @@ private boolean jj_3R_142()
59385867
return false;
59395868
}
59405869

5870+
private boolean jj_3R_184()
5871+
{
5872+
Token xsp;
5873+
xsp = jj_scanpos;
5874+
if (jj_scan_token(37)) {
5875+
jj_scanpos = xsp;
5876+
if (jj_scan_token(38)) return true;
5877+
}
5878+
return false;
5879+
}
5880+
5881+
private boolean jj_3R_182()
5882+
{
5883+
if (jj_scan_token(COMMA)) return true;
5884+
return false;
5885+
}
5886+
59415887
private boolean jj_3R_166()
59425888
{
59435889
if (jj_scan_token(ST)) return true;
@@ -5956,6 +5902,14 @@ private boolean jj_3R_164()
59565902
return false;
59575903
}
59585904

5905+
private boolean jj_3R_140()
5906+
{
5907+
Token xsp;
5908+
xsp = jj_scanpos;
5909+
if (jj_3R_182()) jj_scanpos = xsp;
5910+
return false;
5911+
}
5912+
59595913
private boolean jj_3R_163()
59605914
{
59615915
if (jj_scan_token(TIME)) return true;
@@ -5986,17 +5940,6 @@ private boolean jj_3R_159()
59865940
return false;
59875941
}
59885942

5989-
private boolean jj_3R_184()
5990-
{
5991-
Token xsp;
5992-
xsp = jj_scanpos;
5993-
if (jj_scan_token(37)) {
5994-
jj_scanpos = xsp;
5995-
if (jj_scan_token(38)) return true;
5996-
}
5997-
return false;
5998-
}
5999-
60005943
private boolean jj_3R_158()
60015944
{
60025945
if (jj_scan_token(RELFONTLENGTH)) return true;
@@ -6054,6 +5997,12 @@ private boolean jj_3R_130()
60545997
return false;
60555998
}
60565999

6000+
private boolean jj_3R_186()
6001+
{
6002+
if (jj_scan_token(IDENT)) return true;
6003+
return false;
6004+
}
6005+
60576006
private boolean jj_3R_138()
60586007
{
60596008
Token xsp;
@@ -6124,17 +6073,6 @@ private boolean jj_3R_131()
61246073
return false;
61256074
}
61266075

6127-
private boolean jj_3R_123()
6128-
{
6129-
Token xsp;
6130-
xsp = jj_scanpos;
6131-
if (jj_scan_token(36)) {
6132-
jj_scanpos = xsp;
6133-
if (jj_scan_token(49)) return true;
6134-
}
6135-
return false;
6136-
}
6137-
61386076
private boolean jj_3R_136()
61396077
{
61406078
if (jj_3R_152()) return true;
@@ -6153,12 +6091,6 @@ private boolean jj_3R_134()
61536091
return false;
61546092
}
61556093

6156-
private boolean jj_3R_186()
6157-
{
6158-
if (jj_scan_token(IDENT)) return true;
6159-
return false;
6160-
}
6161-
61626094
private boolean jj_3R_181()
61636095
{
61646096
if (jj_scan_token(UNICODERANGE)) return true;
@@ -6177,6 +6109,17 @@ private boolean jj_3R_149()
61776109
return false;
61786110
}
61796111

6112+
private boolean jj_3R_123()
6113+
{
6114+
Token xsp;
6115+
xsp = jj_scanpos;
6116+
if (jj_scan_token(36)) {
6117+
jj_scanpos = xsp;
6118+
if (jj_scan_token(49)) return true;
6119+
}
6120+
return false;
6121+
}
6122+
61806123
private boolean jj_3R_151()
61816124
{
61826125
if (jj_scan_token(FUNCTIONCALC)) return true;
@@ -6284,15 +6227,6 @@ private boolean jj_3R_132()
62846227
return false;
62856228
}
62866229

6287-
private boolean jj_3_1()
6288-
{
6289-
Token xsp;
6290-
xsp = jj_scanpos;
6291-
if (jj_3R_123()) jj_scanpos = xsp;
6292-
if (jj_scan_token(108)) return true;
6293-
return false;
6294-
}
6295-
62966230
private boolean jj_3R_129()
62976231
{
62986232
Token xsp;
@@ -6336,6 +6270,15 @@ private boolean jj_3R_125()
63366270
return false;
63376271
}
63386272

6273+
private boolean jj_3_1()
6274+
{
6275+
Token xsp;
6276+
xsp = jj_scanpos;
6277+
if (jj_3R_123()) jj_scanpos = xsp;
6278+
if (jj_scan_token(108)) return true;
6279+
return false;
6280+
}
6281+
63396282
private boolean jj_3R_127()
63406283
{
63416284
if (jj_3R_131()) return true;
@@ -6387,6 +6330,78 @@ private boolean jj_3R_176()
63876330
return false;
63886331
}
63896332

6333+
private boolean jj_3R_175()
6334+
{
6335+
if (jj_scan_token(STRING)) return true;
6336+
return false;
6337+
}
6338+
6339+
private boolean jj_3R_174()
6340+
{
6341+
if (jj_3R_183()) return true;
6342+
return false;
6343+
}
6344+
6345+
private boolean jj_3_5()
6346+
{
6347+
if (jj_3R_127()) return true;
6348+
if (jj_scan_token(LPARAN)) return true;
6349+
return false;
6350+
}
6351+
6352+
private boolean jj_3R_173()
6353+
{
6354+
if (jj_3R_152()) return true;
6355+
return false;
6356+
}
6357+
6358+
private boolean jj_3R_172()
6359+
{
6360+
if (jj_3R_151()) return true;
6361+
return false;
6362+
}
6363+
6364+
private boolean jj_3R_187()
6365+
{
6366+
if (jj_3R_129()) return true;
6367+
return false;
6368+
}
6369+
6370+
private boolean jj_3R_139()
6371+
{
6372+
Token xsp;
6373+
xsp = jj_scanpos;
6374+
if (jj_3R_172()) {
6375+
jj_scanpos = xsp;
6376+
if (jj_3R_173()) {
6377+
jj_scanpos = xsp;
6378+
if (jj_3R_174()) {
6379+
jj_scanpos = xsp;
6380+
if (jj_3R_175()) {
6381+
jj_scanpos = xsp;
6382+
if (jj_3R_176()) {
6383+
jj_scanpos = xsp;
6384+
if (jj_3R_177()) {
6385+
jj_scanpos = xsp;
6386+
if (jj_3R_178()) {
6387+
jj_scanpos = xsp;
6388+
if (jj_3R_179()) {
6389+
jj_scanpos = xsp;
6390+
if (jj_3R_180()) {
6391+
jj_scanpos = xsp;
6392+
if (jj_3R_181()) return true;
6393+
}
6394+
}
6395+
}
6396+
}
6397+
}
6398+
}
6399+
}
6400+
}
6401+
}
6402+
return false;
6403+
}
6404+
63906405
/** Generated Token Manager. */
63916406
public CssParserTokenManager token_source;
63926407
SimpleCharStream jj_input_stream;

0 commit comments

Comments
 (0)