Skip to content

Commit 80c6651

Browse files
committed
fix for lab and lch parsing
1 parent ce73f4e commit 80c6651

1 file changed

Lines changed: 33 additions & 19 deletions

File tree

org/w3c/css/values/CssColor.java

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,14 @@ public String toString() {
9191
return rgba.toString();
9292
} else if (hsl != null) {
9393
return hsl.toString();
94-
} else {
94+
} else if (hwb != null) {
9595
return hwb.toString();
96+
} else if (lab != null) {
97+
return lab.toString();
98+
} else if (lch != null) {
99+
return lch.toString();
96100
}
101+
return "*invalid*";
97102
}
98103

99104

@@ -869,7 +874,7 @@ public void setLABColor(CssExpression exp, ApplContext ac)
869874
exp.next();
870875
val = exp.getValue();
871876
op = exp.getOperator();
872-
if (val == null || (op != SPACE && exp.getRemainingCount() > 1)) {
877+
if (val == null) {
873878
exp.starts();
874879
throw new InvalidParamException("invalid-color", ac);
875880
}
@@ -879,12 +884,17 @@ public void setLABColor(CssExpression exp, ApplContext ac)
879884
exp.starts();
880885
throw new InvalidParamException("rgb", val, ac); // FIXME lab
881886
}
882-
hwb.normalize();
883887

884-
// Alpha
885888
exp.next();
886-
val = exp.getValue();
887-
if (val != null) {
889+
if (!exp.end()) {
890+
if (op != COMMA) {
891+
throw new InvalidParamException("operator", exp.toStringFromStart(), ac);
892+
}
893+
// Alpha
894+
val = exp.getValue();
895+
if (val == null) {
896+
throw new InvalidParamException("invalid-color", exp.toStringFromStart(), ac);
897+
}
888898
switch (val.getType()) {
889899
case CssTypes.CSS_NUMBER:
890900
case CssTypes.CSS_PERCENTAGE:
@@ -894,12 +904,12 @@ public void setLABColor(CssExpression exp, ApplContext ac)
894904
exp.starts();
895905
throw new InvalidParamException("rgb", val, ac); // FIXME lab
896906
}
907+
exp.next();
897908
}
898909
// extra values?
899-
exp.next();
900-
if (exp.getValue() != null) {
910+
if (!exp.end()) {
901911
exp.starts();
902-
throw new InvalidParamException("rgb", exp.getValue(), ac);
912+
throw new InvalidParamException("rgb", exp.toStringFromStart(), ac);
903913
}
904914
}
905915

@@ -949,22 +959,26 @@ public void setLCHColor(CssExpression exp, ApplContext ac)
949959
exp.next();
950960
val = exp.getValue();
951961
op = exp.getOperator();
952-
if (val == null || (op != SPACE && exp.getRemainingCount() > 1)) {
953-
exp.starts();
954-
throw new InvalidParamException("invalid-color", ac);
962+
if (val == null) {
963+
throw new InvalidParamException("invalid-color", exp.toStringFromStart(), ac);
955964
}
956965
if (val.getType() == CssTypes.CSS_NUMBER) {
957966
lch.setH(ac, val);
958967
} else {
959968
exp.starts();
960969
throw new InvalidParamException("rgb", val, ac); // FIXME lch
961970
}
962-
hwb.normalize();
963971

964-
// Alpha
965972
exp.next();
966-
val = exp.getValue();
967-
if (val != null) {
973+
if (!exp.end()) {
974+
if (op != COMMA) {
975+
throw new InvalidParamException("operator", exp.toStringFromStart(), ac);
976+
}
977+
// Alpha
978+
val = exp.getValue();
979+
if (val == null) {
980+
throw new InvalidParamException("invalid-color", exp.toStringFromStart(), ac);
981+
}
968982
switch (val.getType()) {
969983
case CssTypes.CSS_NUMBER:
970984
case CssTypes.CSS_PERCENTAGE:
@@ -974,12 +988,12 @@ public void setLCHColor(CssExpression exp, ApplContext ac)
974988
exp.starts();
975989
throw new InvalidParamException("rgb", val, ac); // FIXME lch
976990
}
991+
exp.next();
977992
}
978993
// extra values?
979-
exp.next();
980-
if (exp.getValue() != null) {
994+
if (!exp.end()) {
981995
exp.starts();
982-
throw new InvalidParamException("rgb", exp.getValue(), ac);
996+
throw new InvalidParamException("rgb", exp.toStringFromStart(), ac);
983997
}
984998
}
985999

0 commit comments

Comments
 (0)