зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1237580. NamedNodeMap should only claim to support a name if that name has no uppercase ASCII chars, for HTML elements in HTML documents. r=bkelly
This commit is contained in:
Родитель
f3a9eb4b39
Коммит
bb3116b03d
|
@ -196,6 +196,12 @@ nsDOMAttributeMap::GetSupportedNames(unsigned aFlags,
|
|||
return;
|
||||
}
|
||||
|
||||
// For HTML elements in HTML documents, only include names that are still the
|
||||
// same after ASCII-lowercasing, since our named getter will end up
|
||||
// ASCII-lowercasing the given string.
|
||||
bool lowercaseNamesOnly =
|
||||
mContent->IsHTMLElement() && mContent->IsInHTMLDocument();
|
||||
|
||||
const uint32_t count = mContent->GetAttrCount();
|
||||
bool seenNonAtomName = false;
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
|
@ -204,9 +210,18 @@ nsDOMAttributeMap::GetSupportedNames(unsigned aFlags,
|
|||
nsString qualifiedName;
|
||||
name->GetQualifiedName(qualifiedName);
|
||||
|
||||
if (lowercaseNamesOnly &&
|
||||
nsContentUtils::StringContainsASCIIUpper(qualifiedName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Omit duplicates. We only need to do this check if we've seen a non-atom
|
||||
// name, because that's the only way we can have two identical qualified
|
||||
// names.
|
||||
if (seenNonAtomName && aNames.Contains(qualifiedName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
aNames.AppendElement(qualifiedName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -586,6 +586,10 @@ test(function() {
|
|||
["0", "1", "2"])
|
||||
assert_array_equals(Object.getOwnPropertyNames(el.attributes),
|
||||
["0", "1", "2", "a", "b"])
|
||||
for (var propName of Object.getOwnPropertyNames(el.attributes)) {
|
||||
assert_true(el.attributes[propName] instanceof Attr,
|
||||
"el.attributes has an Attr for property name " + propName);
|
||||
}
|
||||
}, "Own property correctness with non-namespaced attribute before same-name namespaced one");
|
||||
|
||||
test(function() {
|
||||
|
@ -599,6 +603,10 @@ test(function() {
|
|||
["0", "1", "2"])
|
||||
assert_array_equals(Object.getOwnPropertyNames(el.attributes),
|
||||
["0", "1", "2", "a", "b"])
|
||||
for (var propName of Object.getOwnPropertyNames(el.attributes)) {
|
||||
assert_true(el.attributes[propName] instanceof Attr,
|
||||
"el.attributes has an Attr for property name " + propName);
|
||||
}
|
||||
}, "Own property correctness with namespaced attribute before same-name non-namespaced one");
|
||||
|
||||
test(function() {
|
||||
|
@ -612,5 +620,59 @@ test(function() {
|
|||
["0", "1", "2"])
|
||||
assert_array_equals(Object.getOwnPropertyNames(el.attributes),
|
||||
["0", "1", "2", "a:b", "c:d"])
|
||||
for (var propName of Object.getOwnPropertyNames(el.attributes)) {
|
||||
assert_true(el.attributes[propName] instanceof Attr,
|
||||
"el.attributes has an Attr for property name " + propName);
|
||||
}
|
||||
}, "Own property correctness with two namespaced attributes with the same name-with-prefix");
|
||||
|
||||
test(function() {
|
||||
var el = document.createElement("div");
|
||||
el.setAttributeNS("foo", "A:B", "");
|
||||
el.setAttributeNS("bar", "c:D", "");
|
||||
el.setAttributeNS("baz", "e:F", "");
|
||||
el.setAttributeNS("qux", "g:h", "");
|
||||
el.setAttributeNS("", "I", "");
|
||||
el.setAttributeNS("", "j", "");
|
||||
assert_array_equals(Object.getOwnPropertyNames(el.attributes),
|
||||
["0", "1", "2", "3", "4", "5", "g:h", "j"])
|
||||
for (var propName of Object.getOwnPropertyNames(el.attributes)) {
|
||||
assert_true(el.attributes[propName] instanceof Attr,
|
||||
"el.attributes has an Attr for property name " + propName);
|
||||
}
|
||||
}, "Own property names should only include all-lowercase qualified names for an HTML element in an HTML document");
|
||||
|
||||
test(function() {
|
||||
var el = document.createElementNS("", "div");
|
||||
el.setAttributeNS("foo", "A:B", "");
|
||||
el.setAttributeNS("bar", "c:D", "");
|
||||
el.setAttributeNS("baz", "e:F", "");
|
||||
el.setAttributeNS("qux", "g:h", "");
|
||||
el.setAttributeNS("", "I", "");
|
||||
el.setAttributeNS("", "j", "");
|
||||
assert_array_equals(Object.getOwnPropertyNames(el.attributes),
|
||||
["0", "1", "2", "3", "4", "5", "A:B", "c:D", "e:F", "g:h", "I", "j"])
|
||||
for (var propName of Object.getOwnPropertyNames(el.attributes)) {
|
||||
assert_true(el.attributes[propName] instanceof Attr,
|
||||
"el.attributes has an Attr for property name " + propName);
|
||||
}
|
||||
}, "Own property names should include all qualified names for a non-HTML element in an HTML document");
|
||||
|
||||
test(function() {
|
||||
var doc = document.implementation.createDocument(null, "");
|
||||
assert_equals(doc.contentType, "application/xml");
|
||||
var el = doc.createElementNS("http://www.w3.org/1999/xhtml", "div");
|
||||
el.setAttributeNS("foo", "A:B", "");
|
||||
el.setAttributeNS("bar", "c:D", "");
|
||||
el.setAttributeNS("baz", "e:F", "");
|
||||
el.setAttributeNS("qux", "g:h", "");
|
||||
el.setAttributeNS("", "I", "");
|
||||
el.setAttributeNS("", "j", "");
|
||||
assert_array_equals(Object.getOwnPropertyNames(el.attributes),
|
||||
["0", "1", "2", "3", "4", "5", "A:B", "c:D", "e:F", "g:h", "I", "j"])
|
||||
for (var propName of Object.getOwnPropertyNames(el.attributes)) {
|
||||
assert_true(el.attributes[propName] instanceof Attr,
|
||||
"el.attributes has an Attr for property name " + propName);
|
||||
}
|
||||
}, "Own property names should include all qualified names for an HTML element in a non-HTML document");
|
||||
</script>
|
||||
|
|
Загрузка…
Ссылка в новой задаче