Commit 2fcb03d3 authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

Stop parse-time range checking on SVG non-negative lengths in math functions

According to spec (*), we shouldn't perform range checking for
math function at parse time. This patch stops such checking on
SVG lengths.

This also eliminates an improper call of
CSSMathFunctionValue::DoubleValue(), so that we can put runtime
unit type checking in there.

(*) https://drafts.csswg.org/css-values-4/#calc-range

Bug: 979895, 982425
Change-Id: Id7abfcda611c23216127818e7e2473b065116fd6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1693132
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Cr-Commit-Position: refs/heads/master@{#676453}
parent 6fc7b878
...@@ -39,9 +39,13 @@ SVGParsingError SVGAnimatedLength::AttributeChanged(const String& value) { ...@@ -39,9 +39,13 @@ SVGParsingError SVGAnimatedLength::AttributeChanged(const String& value) {
SVGAnimatedProperty<SVGLength>::AttributeChanged(value); SVGAnimatedProperty<SVGLength>::AttributeChanged(value);
if (SVGLength::NegativeValuesForbiddenForAnimatedLengthAttribute( if (SVGLength::NegativeValuesForbiddenForAnimatedLengthAttribute(
AttributeName()) && AttributeName())) {
BaseValue()->ValueInSpecifiedUnits() < 0) // TODO(crbug.com/982425): Pass |kValueRangeNonNegative| to property parser
parse_status = SVGParseStatus::kNegativeValue; // to handle range checking on math functions correctly, and also to avoid
// this ad hoc range checking.
if (BaseValue()->IsNegativeNumericLiteral())
parse_status = SVGParseStatus::kNegativeValue;
}
return parse_status; return parse_status;
} }
......
...@@ -360,4 +360,10 @@ void SVGLength::SetInitial(unsigned initial_value) { ...@@ -360,4 +360,10 @@ void SVGLength::SetInitial(unsigned initial_value) {
value_ = CreateInitialCSSValue(static_cast<Initial>(initial_value)); value_ = CreateInitialCSSValue(static_cast<Initial>(initial_value));
} }
bool SVGLength::IsNegativeNumericLiteral() const {
if (!value_->IsNumericLiteralValue())
return false;
return value_->GetDoubleValue() < 0;
}
} // namespace blink } // namespace blink
...@@ -114,6 +114,7 @@ class SVGLength final : public SVGPropertyBase { ...@@ -114,6 +114,7 @@ class SVGLength final : public SVGPropertyBase {
bool IsFontRelative() const { return value_->IsFontRelativeLength(); } bool IsFontRelative() const { return value_->IsFontRelativeLength(); }
bool IsCalculated() const { return value_->IsCalculated(); } bool IsCalculated() const { return value_->IsCalculated(); }
bool IsNegativeNumericLiteral() const;
bool IsZero() const { return value_->GetFloatValue() == 0; } bool IsZero() const { return value_->GetFloatValue() == 0; }
static SVGLengthMode LengthModeForAnimatedLengthAttribute( static SVGLengthMode LengthModeForAnimatedLengthAttribute(
......
<svg xmlns="http://www.w3.org/2000/svg" width="500" height="500">
<rect x="50" y="50" width="400" height="400" rx="0" ry="0" fill="#00ff00" />
<rect x="150" y="100" width="200" height="300" rx="50" ry="50" fill="#0000ff" />
<rect x="200" y="150" width="100" height="200" rx="50" ry="50" fill="#ff0000" />
</svg>
CONSOLE ERROR: line 4: Error: <rect> attribute ry: A negative value is not valid. ("-100")
<svg xmlns="http://www.w3.org/2000/svg" width="500" height="500">
<rect x="50" y="50" width="400" height="400" rx="calc(-50)" ry="calc(-50)" fill="#00ff00" />
<rect x="150" y="100" width="200" height="300" rx="calc(20% - 50)" ry="50" fill="#0000ff" />
<rect x="200" y="150" width="100" height="200" rx="50" ry="-100" fill="#ff0000" />
</svg>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment