Commit ed7dd589 authored by Ian Kilpatrick's avatar Ian Kilpatrick Committed by Commit Bot

[TableNG] Don't parse zero width attributes on tables.

As above. This patch disallows parsing <table width="0"> mapping to
"width: 0px" internally.

This only applies to width (not height) - see:
https://wpt.fyi/results/html/rendering/dimension-attributes.html?label=master&label=experimental&aligned&q=dimension-attributes

See also:
https://drafts.csswg.org/css-tables-3/#mapping

Bug: 958381
Change-Id: I42844dc7b77b8597f4a256e7739baaa3df9f249b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2458587Reviewed-by: default avatarAleks Totic <atotic@chromium.org>
Reviewed-by: default avatarMason Freed <masonfreed@chromium.org>
Commit-Queue: Ian Kilpatrick <ikilpatrick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#815189}
parent cd0974ca
......@@ -1240,7 +1240,8 @@ void HTMLElement::DidMoveToNewDocument(Document& old_document) {
void HTMLElement::AddHTMLLengthToStyle(MutableCSSPropertyValueSet* style,
CSSPropertyID property_id,
const String& value,
AllowPercentage allow_percentage) {
AllowPercentage allow_percentage,
AllowZero allow_zero) {
HTMLDimension dimension;
if (!ParseDimensionValue(value, dimension))
return;
......@@ -1250,7 +1251,10 @@ void HTMLElement::AddHTMLLengthToStyle(MutableCSSPropertyValueSet* style,
}
if (dimension.IsRelative())
return;
if (dimension.IsPercentage() && allow_percentage != kAllowPercentageValues)
if (dimension.IsPercentage() &&
allow_percentage == kDontAllowPercentageValues)
return;
if (dimension.Value() == 0 && allow_zero == kDontAllowZeroValues)
return;
CSSPrimitiveValue::UnitType unit =
dimension.IsPercentage() ? CSSPrimitiveValue::UnitType::kPercentage
......
......@@ -155,10 +155,12 @@ class CORE_EXPORT HTMLElement : public Element {
protected:
enum AllowPercentage { kDontAllowPercentageValues, kAllowPercentageValues };
enum AllowZero { kDontAllowZeroValues, kAllowZeroValues };
void AddHTMLLengthToStyle(MutableCSSPropertyValueSet*,
CSSPropertyID,
const String& value,
AllowPercentage = kAllowPercentageValues);
AllowPercentage = kAllowPercentageValues,
AllowZero = kAllowZeroValues);
void AddHTMLColorToStyle(MutableCSSPropertyValueSet*,
CSSPropertyID,
const String& color);
......
......@@ -309,7 +309,8 @@ void HTMLTableElement::CollectStyleForPresentationAttribute(
const AtomicString& value,
MutableCSSPropertyValueSet* style) {
if (name == html_names::kWidthAttr) {
AddHTMLLengthToStyle(style, CSSPropertyID::kWidth, value);
AddHTMLLengthToStyle(style, CSSPropertyID::kWidth, value,
kAllowPercentageValues, kDontAllowZeroValues);
} else if (name == html_names::kHeightAttr) {
AddHTMLLengthToStyle(style, CSSPropertyID::kHeight, value);
} else if (name == html_names::kBorderAttr) {
......
This is a testharness.js-based test.
Found 1640 tests; 1621 PASS, 19 FAIL, 0 TIMEOUT, 0 NOTRUN.
Found 1640 tests; 1624 PASS, 16 FAIL, 0 TIMEOUT, 0 NOTRUN.
PASS <hr width="200"> mapping to width
PASS <hr width="1007"> mapping to width
PASS <hr width=" 00523 "> mapping to width
......@@ -717,9 +717,9 @@ PASS <table width=".%"> mapping to width
PASS <table width=".x"> mapping to width
PASS <table width=".5"> mapping to width
PASS <table width=".5%"> mapping to width
FAIL <table width="0"> mapping to width assert_equals: expected "auto" but got "0px"
FAIL <table width="0%"> mapping to width assert_equals: expected "auto" but got "0%"
FAIL <table width="0px"> mapping to width assert_equals: expected "auto" but got "0px"
PASS <table width="0"> mapping to width
PASS <table width="0%"> mapping to width
PASS <table width="0px"> mapping to width
PASS <table height="200"> mapping to height
PASS <table height="1007"> mapping to height
PASS <table height=" 00523 "> mapping to height
......
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