Bug 1375701 - Atomize class attribute value in the parser in the innerHTML case

Tag #1375
This commit is contained in:
Matt A. Tobin 2020-04-17 06:12:55 -04:00 committed by Roy Tam
commit fe13c5bffc
14 changed files with 275 additions and 153 deletions

View file

@ -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;
}