summaryrefslogtreecommitdiff
path: root/layout/style
diff options
context:
space:
mode:
authorFranklinDM <mrmineshafter17@gmail.com>2022-04-22 21:50:17 +0800
committerFranklinDM <mrmineshafter17@gmail.com>2022-04-23 19:34:31 +0800
commit6f685140aa98ef0a4a8ddd6da420ea14f61ea31c (patch)
treed65ef078dfbed3296ec360893e9b19e7f35f168f /layout/style
parent5aa65d2aeab36ea8de8129c0babcf70a5e4e662a (diff)
downloaduxp-6f685140aa98ef0a4a8ddd6da420ea14f61ea31c.tar.gz
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.
Diffstat (limited to 'layout/style')
-rw-r--r--layout/style/nsCSSParser.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/layout/style/nsCSSParser.cpp b/layout/style/nsCSSParser.cpp
index f3df2df208..387f6ed27f 100644
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -2300,8 +2300,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();