Issue #1881 - Interpret empty or whitespace root margin string as zero length

This attempts to get the first non-whitespace token, which if exists, continues with previous behavior of parsing the margin string. Otherwise, if the specified margin string is empty or consists only of whitespace characters, is interpreted as zero length.

IntersectionObserver is the only consumer of the `ParseMarginString` method, as far as I can tell, so this should not affect anything else.

Note: For some reason, Firefox and Chrome treat the unitless zero length as invalid, while with this change, we do not change existing behavior in that regard and continue to accept that value.
This commit is contained in:
FranklinDM 2022-04-22 21:50:17 +08:00 committed by roytam1
commit 37753e32a8

View file

@ -2304,8 +2304,20 @@ CSSParserImpl::ParseMarginString(const nsSubstring& aBuffer,
nsAutoSuppressErrors suppressErrors(this, aSuppressErrors);
// Parse a margin, and check that there's nothing else after it.
bool marginParsed = ParseGroupedBoxProperty(VARIANT_LP, aValue, 0) && !GetToken(true);
bool marginParsed = false;
// Treat margin as zero length if there are no tokens, i.e., the specified
// margin string is empty or consists only of whitespace characters.
if (!GetToken(true)) {
nsCSSRect& zeroRootMargin = aValue.SetRectValue();
zeroRootMargin.SetAllSidesTo(nsCSSValue(0.0f, eCSSUnit_Pixel));
marginParsed = true;
} else {
UngetToken();
// Parse a margin, and check that there's nothing else after it.
marginParsed = ParseGroupedBoxProperty(VARIANT_LP, aValue, 0) &&
!GetToken(true);
}
if (aSuppressErrors) {
CLEAR_ERROR();