Title: [292816] trunk
- Revision
- 292816
- Author
- an...@apple.com
- Date
- 2022-04-13 11:48:19 -0700 (Wed, 13 Apr 2022)
Log Message
[CSS Container Queries] Limit query range syntax
https://bugs.webkit.org/show_bug.cgi?id=239118
Reviewed by Simon Fraser.
LayoutTests/imported/w3c:
* web-platform-tests/css/css-contain/container-queries/at-container-parsing-expected.txt:
Source/WebCore:
The spec disallows things like (100px = width < 200px) and (100px < width > 200px).
https://www.w3.org/TR/mediaqueries-4/#mq-range-context
* css/ContainerQueryParser.cpp:
(WebCore::ContainerQueryParser::consumeContainerQuery):
Try as a condition first.
Return UnknownQuery on parse failure.
(WebCore::ContainerQueryParser::consumeRangeSizeFeature):
Validate the ranges so what ends up being allowed matches the spec productions.
Modified Paths
Diff
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (292815 => 292816)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2022-04-13 18:17:55 UTC (rev 292815)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2022-04-13 18:48:19 UTC (rev 292816)
@@ -1,3 +1,12 @@
+2022-04-13 Antti Koivisto <an...@apple.com>
+
+ [CSS Container Queries] Limit query range syntax
+ https://bugs.webkit.org/show_bug.cgi?id=239118
+
+ Reviewed by Simon Fraser.
+
+ * web-platform-tests/css/css-contain/container-queries/at-container-parsing-expected.txt:
+
2022-04-13 Youenn Fablet <you...@apple.com>
Complement implementation of step 5.5 of https://fetch.spec.whatwg.org/#http-fetch
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/at-container-parsing-expected.txt (292815 => 292816)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/at-container-parsing-expected.txt 2022-04-13 18:17:55 UTC (rev 292815)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/at-container-parsing-expected.txt 2022-04-13 18:48:19 UTC (rev 292816)
@@ -51,13 +51,13 @@
PASS size(grid)
PASS (grid)
PASS (width == 100px)
-FAIL (100px == width) assert_equals: expected 2 but got 0
-FAIL (100px = width = 200px) assert_equals: expected "" but got "true"
-FAIL (100px < width > 200px) assert_equals: expected "" but got "true"
-FAIL (100px <= width >= 200px) assert_equals: expected "" but got "true"
-FAIL (100px <= width > 200px) assert_equals: expected "" but got "true"
-FAIL (100px < width >= 200px) assert_equals: expected "" but got "true"
-FAIL (100px : width : 200px) assert_equals: expected 2 but got 0
+PASS (100px == width)
+PASS (100px = width = 200px)
+PASS (100px < width > 200px)
+PASS (100px <= width >= 200px)
+PASS (100px <= width > 200px)
+PASS (100px < width >= 200px)
+PASS (100px : width : 200px)
PASS screen
PASS print
PASS not print
Modified: trunk/Source/WebCore/ChangeLog (292815 => 292816)
--- trunk/Source/WebCore/ChangeLog 2022-04-13 18:17:55 UTC (rev 292815)
+++ trunk/Source/WebCore/ChangeLog 2022-04-13 18:48:19 UTC (rev 292816)
@@ -1,3 +1,24 @@
+2022-04-13 Antti Koivisto <an...@apple.com>
+
+ [CSS Container Queries] Limit query range syntax
+ https://bugs.webkit.org/show_bug.cgi?id=239118
+
+ Reviewed by Simon Fraser.
+
+ The spec disallows things like (100px = width < 200px) and (100px < width > 200px).
+
+ https://www.w3.org/TR/mediaqueries-4/#mq-range-context
+
+ * css/ContainerQueryParser.cpp:
+ (WebCore::ContainerQueryParser::consumeContainerQuery):
+
+ Try as a condition first.
+ Return UnknownQuery on parse failure.
+
+ (WebCore::ContainerQueryParser::consumeRangeSizeFeature):
+
+ Validate the ranges so what ends up being allowed matches the spec productions.
+
2022-04-13 Simon Fraser <simon.fra...@apple.com>
[css-scroll-snap] scrollIntoView fails with scroll-snap-type on :root
Modified: trunk/Source/WebCore/css/ContainerQueryParser.cpp (292815 => 292816)
--- trunk/Source/WebCore/css/ContainerQueryParser.cpp 2022-04-13 18:17:55 UTC (rev 292815)
+++ trunk/Source/WebCore/css/ContainerQueryParser.cpp 2022-04-13 18:48:19 UTC (rev 292816)
@@ -73,13 +73,15 @@
blockRange.consumeWhitespace();
- // Try to parse as a size query first.
- auto blockForSizeFeature = blockRange;
- if (auto sizeFeature = consumeSizeFeature(blockForSizeFeature))
+ // Try to parse as a condition first.
+ auto conditionRange = blockRange;
+ if (auto condition = consumeCondition<CQ::ContainerCondition>(conditionRange))
+ return { condition };
+
+ if (auto sizeFeature = consumeSizeFeature(blockRange))
return { *sizeFeature };
- if (auto condition = consumeCondition<CQ::ContainerCondition>(blockRange))
- return { condition };
+ return CQ::UnknownQuery { { }, blockRange.serialize() };
}
return { };
@@ -155,6 +157,10 @@
};
auto sizeFeature = consume();
+
+ if (!range.atEnd())
+ return { };
+
if (sizeFeature)
m_requiredAxes.add(CQ::requiredAxesForFeature(sizeFeature->name));
@@ -203,6 +209,8 @@
return { };
auto value = consumeValue(range);
+ if (!value)
+ return { };
return CQ::SizeFeature { featureName, CQ::Syntax::Colon, { }, CQ::Comparison { op, WTFMove(value) } };
}
@@ -239,13 +247,19 @@
}
};
+ bool didFailParsing = false;
+
auto consumeLeftComparison = [&]() -> std::optional<CQ::Comparison> {
if (range.peek().type() == IdentToken)
return { };
auto value = consumeValue(range);
+ if (!value)
+ return { };
auto op = consumeRangeOperator();
- if (!op)
+ if (!op) {
+ didFailParsing = true;
return { };
+ }
return CQ::Comparison { *op, WTFMove(value) };
};
@@ -255,6 +269,10 @@
if (!op)
return { };
auto value = consumeValue(range);
+ if (!value) {
+ didFailParsing = true;
+ return { };
+ }
return CQ::Comparison { *op, WTFMove(value) };
};
@@ -267,7 +285,23 @@
auto rightComparison = consumeRightComparison();
- if (!leftComparison && !rightComparison)
+ auto validateComparisons = [&] {
+ if (didFailParsing)
+ return false;
+ if (!leftComparison && !rightComparison)
+ return false;
+ if (!leftComparison || !rightComparison)
+ return true;
+ // Disallow comparisons like (a=b=c), (a=b<c).
+ if (leftComparison->op == CQ::ComparisonOperator::Equal || rightComparison->op == CQ::ComparisonOperator::Equal)
+ return false;
+ // Disallow comparisons like (a<b>c).
+ bool leftIsLess = leftComparison->op == CQ::ComparisonOperator::LessThan || leftComparison->op == CQ::ComparisonOperator::LessThanOrEqual;
+ bool rightIsLess = rightComparison->op == CQ::ComparisonOperator::LessThan || rightComparison->op == CQ::ComparisonOperator::LessThanOrEqual;
+ return leftIsLess == rightIsLess;
+ };
+
+ if (!validateComparisons())
return { };
return CQ::SizeFeature { WTFMove(featureName), CQ::Syntax::Range, WTFMove(leftComparison), WTFMove(rightComparison) };
@@ -283,7 +317,6 @@
return value;
if (auto value = CSSPropertyParserHelpers::consumeAspectRatioValue(range))
return value;
- range.consumeIncludingWhitespace();
return nullptr;
}
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes