From f4a1d0123c41647f2f05aeaa2ae14bd1806fbb5c Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 17 Apr 2020 06:12:55 -0400 Subject: Bug 1375701 - Atomize class attribute value in the parser in the innerHTML case Tag #1375 --- parser/html/nsHtml5Portability.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'parser/html/nsHtml5Portability.cpp') diff --git a/parser/html/nsHtml5Portability.cpp b/parser/html/nsHtml5Portability.cpp index 5a76b3c56..400f06204 100644 --- a/parser/html/nsHtml5Portability.cpp +++ b/parser/html/nsHtml5Portability.cpp @@ -16,12 +16,30 @@ nsHtml5Portability::newLocalNameFromBuffer(char16_t* buf, int32_t offset, int32_ return interner->GetAtom(nsDependentSubstring(buf, buf + length)); } +static bool +ContainsWhiteSpace(mozilla::Span aSpan) +{ + for (char16_t c : aSpan) { + if (nsContentUtils::IsHTMLWhitespace(c)) { + return true; + } + } + return false; +} + nsHtml5String nsHtml5Portability::newStringFromBuffer(char16_t* buf, int32_t offset, int32_t length, - nsHtml5TreeBuilder* treeBuilder) + nsHtml5TreeBuilder* treeBuilder, + bool maybeAtomize) { + if (!length) { + return nsHtml5String::EmptyString(); + } + if (maybeAtomize && !ContainsWhiteSpace(mozilla::MakeSpan(buf + offset, length))) { + return nsHtml5String::FromAtom(NS_AtomizeMainThread(nsDependentSubstring(buf + offset, length))); + } return nsHtml5String::FromBuffer(buf + offset, length, treeBuilder); } -- cgit v1.2.3