Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Unified Diff: Source/core/dom/Attr.cpp

Issue 1073823002: Correctly handle updates over attached Attrs involving null values. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/dom/Attr.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/Attr.cpp
diff --git a/Source/core/dom/Attr.cpp b/Source/core/dom/Attr.cpp
index a2641d205c594a6597ef5976daf124e11d7c2f68..3c09bc29ee4d8ae97f91bede5917fbad14b45593 100644
--- a/Source/core/dom/Attr.cpp
+++ b/Source/core/dom/Attr.cpp
@@ -111,7 +111,7 @@ void Attr::setValue(const AtomicString& value)
// attributes as the JS callback could alter the attributes and leave us in a bad state.
removeChildren(OmitSubtreeModifiedEvent);
if (m_element)
- elementAttribute().setValue(value);
+ updateElementAttribute(value);
else
m_standaloneValueOrAttachedLocalName = value;
createTextChild();
@@ -187,7 +187,7 @@ void Attr::childrenChanged(const ChildrenChange&)
m_element->willModifyAttribute(qualifiedName(), value(), newValue);
if (m_element)
- elementAttribute().setValue(newValue);
+ updateElementAttribute(newValue);
else
m_standaloneValueOrAttachedLocalName = newValue;
@@ -202,11 +202,19 @@ const AtomicString& Attr::value() const
return m_standaloneValueOrAttachedLocalName;
}
-Attribute& Attr::elementAttribute()
+void Attr::updateElementAttribute(const AtomicString& value)
{
ASSERT(m_element);
ASSERT(m_element->elementData());
- return *m_element->ensureUniqueElementData().attributes().find(qualifiedName());
+ MutableAttributeCollection attributes = m_element->ensureUniqueElementData().attributes();
+ size_t index = attributes.findIndex(qualifiedName());
+ if (index == kNotFound) {
+ // Element attributes with null values are not stored.
+ if (!value.isNull())
+ attributes.append(qualifiedName(), value);
+ return;
+ }
+ return attributes[index].setValue(value);
}
void Attr::detachFromElementWithValue(const AtomicString& value)
« no previous file with comments | « Source/core/dom/Attr.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698