Skip to content

Commit ad4b711

Browse files
committed
fix aspect-ratio allowing also only one number, fix w3c#381 (and validator/validator#1406 )
1 parent fef61cf commit ad4b711

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

org/w3c/css/properties/css3/CssAspectRatio.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ public CssAspectRatio(ApplContext ac, CssExpression expression, boolean check)
104104
expression.next();
105105
}
106106
// if things are not entirely parsed
107-
if (v.size() == 0 || (ratio_state != 0 && ratio_state != 3)) {
107+
if (ratio_state == 1) {
108+
// so we got only one number
109+
v.add(new CssRatio(dividend));
110+
} else if (v.isEmpty() || (ratio_state != 0 && ratio_state != 3)) {
108111
throw new InvalidParamException("value",
109112
expression.toStringFromStart(),
110113
getPropertyName(), ac);

org/w3c/css/values/CssRatio.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ public CssRatio(CssValue gw, BigDecimal h) {
6565
this.h = h;
6666
}
6767

68+
public CssRatio(CssValue gw) {
69+
if (gw.getRawType() == CssTypes.CSS_NUMBER) {
70+
try {
71+
this.w = gw.getNumber().getBigDecimalValue();
72+
} catch (Exception ex) {
73+
this.gw = gw;
74+
}
75+
} else {
76+
this.gw = gw;
77+
}
78+
}
79+
6880
public CssRatio(CssValue gw, CssValue gh) {
6981
if (gw.getRawType() == CssTypes.CSS_NUMBER) {
7082
try {
@@ -145,6 +157,9 @@ public String toString() {
145157
} else {
146158
sb.append(gw.toString()).append(' ');
147159
}
160+
if (h == null && gh == null) {
161+
return sb.toString();
162+
}
148163
sb.append('/');
149164
if (h != null) {
150165
sb.append(h.toPlainString());
@@ -163,6 +178,9 @@ public boolean equals(Object value) {
163178
try {
164179
CssRatio other = (CssRatio) value;
165180
// check that the ratio are the same
181+
if (h == null && gh == null) {
182+
return (other.h == null) && (other.gh == null) && (w.compareTo(other.w) == 0);
183+
}
166184
BigDecimal ratio, other_ratio;
167185
ratio = w.divide(h, RoundingMode.CEILING);
168186
other_ratio = other.w.divide(other.h, RoundingMode.CEILING);

0 commit comments

Comments
 (0)