diff options
author | FranklinDM <mrmineshafter17@gmail.com> | 2022-04-22 10:06:34 -0500 |
---|---|---|
committer | Matt A. Tobin <email@mattatobin.com> | 2022-04-22 10:07:02 -0500 |
commit | c89bbcef39fb605460edc2f8d3b447eff72b074d (patch) | |
tree | a55891ccbba6f2b8bad5a90c83184523c6b4b383 | |
parent | 465f4eb3a68ef3fdd894dafc4a6b9ce7fd7ccf8c (diff) | |
download | aura-central-c89bbcef39fb605460edc2f8d3b447eff72b074d.tar.gz |
[DOM:Base] Interpret empty margin string as a zero root
margin in the IntersectionObserver
This trims the whitespace from the margin string first before checking if it is empty, after which, it will be interpreted as a zero root margin. Otherwise, continue with previous behavior (parse margin string using the CSS Parser).
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.
Reported on, but does not use any code from https://bugzilla.mozilla.org/show_bug.cgi?id=1738791
-rw-r--r-- | dom/base/DOMIntersectionObserver.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/dom/base/DOMIntersectionObserver.cpp b/dom/base/DOMIntersectionObserver.cpp index bc8f030d0..1d236c23e 100644 --- a/dom/base/DOMIntersectionObserver.cpp +++ b/dom/base/DOMIntersectionObserver.cpp @@ -118,7 +118,14 @@ DOMIntersectionObserver::SetRootMargin(const nsAString& aString) // mode so that pixel/percent and unit-less values will be differentiated. nsCSSParser parser(nullptr); nsCSSValue value; - if (!parser.ParseMarginString(aString, nullptr, 0, value, true)) { + + // Use a zero margin if the input string is empty after trimming whitespace + const nsAString& stringNoWS = + nsContentUtils::TrimWhitespace<nsContentUtils::IsHTMLWhitespaceOrNBSP>(aString, true); + if (stringNoWS.IsEmpty()) { + nsCSSRect& zeroRootMargin = value.SetRectValue(); + zeroRootMargin.SetAllSidesTo(nsCSSValue(0.0f, eCSSUnit_Pixel)); + } else if (!parser.ParseMarginString(aString, nullptr, 0, value, true)) { return false; } |