Skip to content

Commit e70e3bf

Browse files
committed
fixed issue with fallback value not being parsed, fixed toString extra space, check that the fallback value is compatible with its type definition
1 parent 97323a4 commit e70e3bf

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

org/w3c/css/util/Messages.properties.en

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,4 +421,5 @@ error.operandnumber: One operand must be a number
421421
error.divisortype: The divisor must be a number
422422
error.incompatibletypes: The types are incompatible
423423
error.invalidtype: Invalid type: %s
424+
error.typevaluemismatch: The value %s is incompatible with its type definition <%s>
424425

org/w3c/css/util/Messages.properties.fr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,3 +445,4 @@ error.operandnumber: Au moins une opérande doit être un nombre
445445
error.divisortype: Le diviseur doit être un nombre
446446
error.incompatibletypes: Les types ne sont pas compatibles
447447
error.invalidtype: Type invalide: %s
448+
error.typevaluemismatch: La valeur %s est incompatible avec sa définition de type <%s>

org/w3c/css/values/CssAttr.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,31 @@ public void setValue(CssExpression exp, ApplContext ac)
136136
val.toString(), "attr()", ac);
137137
case COMMA:
138138
fallback_value = val;
139+
// we should have a computed_type by then.
140+
// let's check the value.
141+
if (fallback_value.getType() != computed_type) {
142+
// deal with percentage and numbers
143+
int fb_type = fallback_value.getType();
144+
// only 0 can be something else than a plain number.
145+
if (fb_type == CssTypes.CSS_NUMBER) {
146+
// TODO check if zero in CssCheckableValue
147+
if (true /*fallback_value.getCheckableValue().isZero()(*/) {
148+
break;
149+
}
150+
}
151+
if (fb_type == CssTypes.CSS_PERCENTAGE) {
152+
if ((computed_type == CssTypes.CSS_LENGTH) ||
153+
(computed_type == CssTypes.CSS_ANGLE) ||
154+
(computed_type == CssTypes.CSS_FREQUENCY) ||
155+
(computed_type == CssTypes.CSS_NUMBER) ||
156+
(computed_type == CssTypes.CSS_TIME)) {
157+
break;
158+
}
159+
}
160+
// else, invalid type
161+
throw new InvalidParamException("typevaluemismatch",
162+
fallback_value, value_type, ac);
163+
}
139164
break;
140165
default:
141166
throw new InvalidParamException("operator",
@@ -145,7 +170,6 @@ public void setValue(CssExpression exp, ApplContext ac)
145170
op = exp.getOperator();
146171
exp.next();
147172
}
148-
// TODO do type checking between the fallback value and the type
149173
}
150174

151175
private int _checkType(CssIdent ident)
@@ -175,7 +199,7 @@ public String toString() {
175199
sb.append(' ').append(value_type);
176200
}
177201
if (fallback_value != null) {
178-
sb.append(" , ").append(fallback_value);
202+
sb.append(", ").append(fallback_value);
179203
}
180204
sb.append(')');
181205
_ts = sb.toString();

0 commit comments

Comments
 (0)