diff options
author | Matt A. Tobin <email@mattatobin.com> | 2020-04-17 06:12:55 -0400 |
---|---|---|
committer | Matt A. Tobin <email@mattatobin.com> | 2020-04-17 06:12:55 -0400 |
commit | f4a1d0123c41647f2f05aeaa2ae14bd1806fbb5c (patch) | |
tree | ff5eca8099cbf057f1aa734c951c8fecd14a165a /parser/html/nsHtml5TreeOperation.cpp | |
parent | 675dce947209afa61950777a7e13016604b3fdb1 (diff) | |
download | uxp-f4a1d0123c41647f2f05aeaa2ae14bd1806fbb5c.tar.gz |
Bug 1375701 - Atomize class attribute value in the parser in the innerHTML case
Tag #1375
Diffstat (limited to 'parser/html/nsHtml5TreeOperation.cpp')
-rw-r--r-- | parser/html/nsHtml5TreeOperation.cpp | 88 |
1 files changed, 53 insertions, 35 deletions
diff --git a/parser/html/nsHtml5TreeOperation.cpp b/parser/html/nsHtml5TreeOperation.cpp index 22c8058595..46907d3a4a 100644 --- a/parser/html/nsHtml5TreeOperation.cpp +++ b/parser/html/nsHtml5TreeOperation.cpp @@ -361,29 +361,34 @@ nsHtml5TreeOperation::SetHTMLElementAttributes(dom::Element* aElement, nsIAtom* aName, nsHtml5HtmlAttributes* aAttributes) { - int32_t len = aAttributes->getLength(); + int32_t len = aAttributes->getLength(); for (int32_t i = 0; i < len; i++) { - // prefix doesn't need regetting. it is always null or a static atom - // local name is never null - nsCOMPtr<nsIAtom> localName = - Reget(aAttributes->getLocalNameNoBoundsCheck(i)); - nsCOMPtr<nsIAtom> prefix = aAttributes->getPrefixNoBoundsCheck(i); - int32_t nsuri = aAttributes->getURINoBoundsCheck(i); + nsHtml5String val = aAttributes->getValueNoBoundsCheck(i); + nsIAtom* klass = val.MaybeAsAtom(); + if (klass) { + aElement->SetSingleClassFromParser(klass); + } else { + // prefix doesn't need regetting. it is always null or a static atom + // local name is never null + RefPtr<nsIAtom> localName = + Reget(aAttributes->getLocalNameNoBoundsCheck(i)); + RefPtr<nsIAtom> prefix = aAttributes->getPrefixNoBoundsCheck(i); + int32_t nsuri = aAttributes->getURINoBoundsCheck(i); - nsString value; // Not Auto, because using it to hold nsStringBuffer* - aAttributes->getValueNoBoundsCheck(i).ToString(value); - if (nsHtml5Atoms::a == aName && nsHtml5Atoms::name == localName) { - // This is an HTML5-incompliant Geckoism. - // Remove when fixing bug 582361 - NS_ConvertUTF16toUTF8 cname(value); - NS_ConvertUTF8toUTF16 uv(nsUnescape(cname.BeginWriting())); - aElement->SetAttr(nsuri, + nsString value; // Not Auto, because using it to hold nsStringBuffer* + val.ToString(value); + if (nsGkAtoms::a == aName && nsGkAtoms::name == localName) { + // This is an HTML5-incompliant Geckoism. + // Remove when fixing bug 582361 + NS_ConvertUTF16toUTF8 cname(value); + NS_ConvertUTF8toUTF16 uv(nsUnescape(cname.BeginWriting())); + aElement->SetAttr(nsuri, localName, prefix, uv, false); - } else { - aElement->SetAttr(nsuri, + } else { + aElement->SetAttr(nsuri, localName, prefix, value, @@ -391,6 +396,7 @@ nsHtml5TreeOperation::SetHTMLElementAttributes(dom::Element* aElement, } } } +} nsIContent* nsHtml5TreeOperation::CreateHTMLElement( @@ -580,16 +586,22 @@ nsHtml5TreeOperation::CreateSVGElement( int32_t len = aAttributes->getLength(); for (int32_t i = 0; i < len; i++) { - // prefix doesn't need regetting. it is always null or a static atom - // local name is never null - nsCOMPtr<nsIAtom> localName = - Reget(aAttributes->getLocalNameNoBoundsCheck(i)); - nsCOMPtr<nsIAtom> prefix = aAttributes->getPrefixNoBoundsCheck(i); - int32_t nsuri = aAttributes->getURINoBoundsCheck(i); + nsHtml5String val = aAttributes->getValueNoBoundsCheck(i); + nsIAtom* klass = val.MaybeAsAtom(); + if (klass) { + newContent->SetSingleClassFromParser(klass); + } else { + // prefix doesn't need regetting. it is always null or a static atom + // local name is never null + nsCOMPtr<nsIAtom> localName = + Reget(aAttributes->getLocalNameNoBoundsCheck(i)); + nsCOMPtr<nsIAtom> prefix = aAttributes->getPrefixNoBoundsCheck(i); + int32_t nsuri = aAttributes->getURINoBoundsCheck(i); - nsString value; // Not Auto, because using it to hold nsStringBuffer* - aAttributes->getValueNoBoundsCheck(i).ToString(value); - newContent->SetAttr(nsuri, localName, prefix, value, false); + nsString value; // Not Auto, because using it to hold nsStringBuffer* + val.ToString(value); + newContent->SetAttr(nsuri, localName, prefix, value, false); + } } return newContent; } @@ -618,16 +630,22 @@ nsHtml5TreeOperation::CreateMathMLElement(nsIAtom* aName, int32_t len = aAttributes->getLength(); for (int32_t i = 0; i < len; i++) { - // prefix doesn't need regetting. it is always null or a static atom - // local name is never null - nsCOMPtr<nsIAtom> localName = - Reget(aAttributes->getLocalNameNoBoundsCheck(i)); - nsCOMPtr<nsIAtom> prefix = aAttributes->getPrefixNoBoundsCheck(i); - int32_t nsuri = aAttributes->getURINoBoundsCheck(i); + nsHtml5String val = aAttributes->getValueNoBoundsCheck(i); + nsIAtom* klass = val.MaybeAsAtom(); + if (klass) { + newContent->SetSingleClassFromParser(klass); + } else { + // prefix doesn't need regetting. it is always null or a static atom + // local name is never null + nsCOMPtr<nsIAtom> localName = + Reget(aAttributes->getLocalNameNoBoundsCheck(i)); + nsCOMPtr<nsIAtom> prefix = aAttributes->getPrefixNoBoundsCheck(i); + int32_t nsuri = aAttributes->getURINoBoundsCheck(i); - nsString value; // Not Auto, because using it to hold nsStringBuffer* - aAttributes->getValueNoBoundsCheck(i).ToString(value); - newContent->SetAttr(nsuri, localName, prefix, value, false); + nsString value; // Not Auto, because using it to hold nsStringBuffer* + val.ToString(value); + newContent->SetAttr(nsuri, localName, prefix, value, false); + } } return newContent; } |