Skip to content
Permalink
Browse files
-webkit-radial-gradient parsing accidentally treats a number of manda…
…tory commas as optional

https://bugs.webkit.org/show_bug.cgi?id=247649
rdar://problem/102111231

Reviewed by Sam Weinig.

* LayoutTests/imported/w3c/web-platform-tests/compat/webkit-gradient-comma-expected.txt:
Expect PASS.

* Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:
(WebCore::CSSPropertyParserHelpers::consumePrefixedRadialGradient): Rearranged the comma parsing
so it matches the grammar, and fail if the commas are missing.

Canonical link: https://commits.webkit.org/256468@main
  • Loading branch information
darinadler committed Nov 9, 2022
1 parent 91f56dc commit a62f77706c4f564444d9f5a36a1e0a295d050692
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
@@ -1,4 +1,4 @@

PASS -webkit-radial-gradient accepts comma before color stops.
FAIL -webkit-radial-gradient rejects missing comma before color stops. assert_false: expected false got true
PASS -webkit-radial-gradient rejects missing comma before color stops.

@@ -3671,29 +3671,27 @@ static RefPtr<CSSValue> consumePrefixedRadialGradient(CSSParserTokenRange& range
extentKeyword = consumeIdentUsingMapping(range, extentMap);
if (!shapeKeyword)
shapeKeyword = consumeIdentUsingMapping(range, shapeMap);
if (shapeKeyword || extentKeyword) {
if (!consumeCommaIncludingWhitespace(range))
return nullptr;
}
}

CSSPrefixedRadialGradientValue::GradientBox gradientBox = std::monostate { };

if (shapeKeyword && extentKeyword) {
consumeCommaIncludingWhitespace(range);

gradientBox = CSSPrefixedRadialGradientValue::ShapeAndExtent { *shapeKeyword, *extentKeyword };
} else if (shapeKeyword) {
consumeCommaIncludingWhitespace(range);

gradientBox = *shapeKeyword;
} else if (extentKeyword) {
consumeCommaIncludingWhitespace(range);

gradientBox = *extentKeyword;
} else {
if (auto length1 = consumeLengthOrPercent(range, context.mode, ValueRange::NonNegative)) {
auto length2 = consumeLengthOrPercent(range, context.mode, ValueRange::NonNegative);
if (!length2)
return nullptr;
consumeCommaIncludingWhitespace(range);

if (!consumeCommaIncludingWhitespace(range))
return nullptr;
gradientBox = CSSPrefixedRadialGradientValue::MeasuredSize { { length1.releaseNonNull(), length2.releaseNonNull() } };
}
}
@@ -3703,14 +3701,8 @@ static RefPtr<CSSValue> consumePrefixedRadialGradient(CSSParserTokenRange& range
return nullptr;

auto colorInterpolationMethod = CSSGradientColorInterpolationMethod::legacyMethod(gradientAlphaPremultiplication(context));
return CSSPrefixedRadialGradientValue::create({
WTFMove(gradientBox),
WTFMove(position)
},
repeating,
colorInterpolationMethod,
WTFMove(*stops)
);
return CSSPrefixedRadialGradientValue::create({ WTFMove(gradientBox), WTFMove(position) },
repeating, colorInterpolationMethod, WTFMove(*stops));
}

static CSSGradientColorInterpolationMethod computeGradientColorInterpolationMethod(const CSSParserContext& context, std::optional<ColorInterpolationMethod> parsedColorInterpolationMethod, const CSSGradientColorStopList& stops)

0 comments on commit a62f777

Please sign in to comment.