Skip to content

Commit a1b4a0c

Browse files
committed
enforce [0..100] in color-mix()
1 parent e30972b commit a1b4a0c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

org/w3c/css/values/color/ColorMix.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99
import org.w3c.css.util.ApplContext;
1010
import org.w3c.css.util.CssVersion;
1111
import org.w3c.css.util.InvalidParamException;
12+
import org.w3c.css.values.CssCheckableValue;
1213
import org.w3c.css.values.CssColor;
1314
import org.w3c.css.values.CssExpression;
1415
import org.w3c.css.values.CssIdent;
1516
import org.w3c.css.values.CssOperator;
17+
import org.w3c.css.values.CssPercentage;
1618
import org.w3c.css.values.CssTypes;
1719
import org.w3c.css.values.CssValue;
1820
import org.w3c.css.values.CssValueList;
1921

22+
import java.math.BigDecimal;
2023
import java.util.ArrayList;
2124

2225
import static org.w3c.css.values.CssOperator.COMMA;
@@ -230,6 +233,18 @@ static public CssValue parseColorPercentageValue(ApplContext ac, CssExpression e
230233
op = exp.getOperator();
231234
if (val.getType() == CssTypes.CSS_PERCENTAGE) {
232235
gotPercentage = true;
236+
CssCheckableValue v = val.getCheckableValue();
237+
if (!v.isPositive()) {
238+
throw new InvalidParamException("value", val.toString(), exp.toStringFromStart(), ac);
239+
}
240+
if (val.getRawType() == CssTypes.CSS_PERCENTAGE) {
241+
CssPercentage p = val.getPercentage();
242+
BigDecimal other = BigDecimal.valueOf(100);
243+
if (p.getValue().compareTo(other) > 0) {
244+
throw new InvalidParamException("lowerequal",
245+
exp.toStringFromStart(), other.toPlainString(), ac);
246+
}
247+
}
233248
values.add(val);
234249
} else {
235250
CssExpression e = new CssExpression();
@@ -248,6 +263,19 @@ static public CssValue parseColorPercentageValue(ApplContext ac, CssExpression e
248263
if (gotPercentage) {
249264
throw new InvalidParamException("value", val.toString(), caller, ac);
250265
}
266+
CssCheckableValue v = val.getCheckableValue();
267+
if (!v.isPositive()) {
268+
throw new InvalidParamException("value", val.toString(),
269+
exp.toStringFromStart(), ac);
270+
}
271+
if (val.getRawType() == CssTypes.CSS_PERCENTAGE) {
272+
CssPercentage p = val.getPercentage();
273+
BigDecimal other = BigDecimal.valueOf(100);
274+
if (p.getValue().compareTo(other) > 0) {
275+
throw new InvalidParamException("lowerequal",
276+
exp.toStringFromStart(), other.toPlainString(), ac);
277+
}
278+
}
251279
values.add(val);
252280
} else {
253281
if (!gotPercentage) {

0 commit comments

Comments
 (0)