aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/element.rs
diff options
context:
space:
mode:
authorKeith Yeung <kungfukeith11@gmail.com>2024-02-20 10:28:25 +0800
committerGitHub <noreply@github.com>2024-02-20 02:28:25 +0000
commitb9935188927b5ab294ae8bf68a848d254e66aa28 (patch)
treee11488b05d901aaf354ebc371551fe090110c55c /components/script/dom/element.rs
parent5b7ee86fd1ac8fe6169f8a01639b57c25e22b44e (diff)
downloadservo-b9935188927b5ab294ae8bf68a848d254e66aa28.tar.gz
servo-b9935188927b5ab294ae8bf68a848d254e66aa28.zip
Check for XML and XMLS namespace during 'locating a namespace' (#31374)
* Check for XML and XMLS namespace during 'locating a namespace' * Address review comments * Remove test expectation in legacy layout meta
Diffstat (limited to 'components/script/dom/element.rs')
-rw-r--r--components/script/dom/element.rs25
1 files changed, 21 insertions, 4 deletions
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs
index f3d3ebecb69..982976e9361 100644
--- a/components/script/dom/element.rs
+++ b/components/script/dom/element.rs
@@ -1190,23 +1190,40 @@ impl Element {
// Element branch of https://dom.spec.whatwg.org/#locate-a-namespace
pub fn locate_namespace(&self, prefix: Option<DOMString>) -> Namespace {
- let prefix = prefix.map(String::from).map(LocalName::from);
+ let namespace_prefix = prefix.clone().map(|s| Prefix::from(&*s));
+
+ // "1. If prefix is "xml", then return the XML namespace."
+ if namespace_prefix == Some(namespace_prefix!("xml")) {
+ return ns!(xml);
+ }
+
+ // "2. If prefix is "xmlns", then return the XMLNS namespace."
+ if namespace_prefix == Some(namespace_prefix!("xmlns")) {
+ return ns!(xmlns);
+ }
+
+ let prefix = prefix.map(|s| LocalName::from(&*s));
let inclusive_ancestor_elements = self
.upcast::<Node>()
.inclusive_ancestors(ShadowIncluding::No)
.filter_map(DomRoot::downcast::<Self>);
- // Steps 3-4.
+ // "5. If its parent element is null, then return null."
+ // "6. Return the result of running locate a namespace on its parent element using prefix."
for element in inclusive_ancestor_elements {
- // Step 1.
+ // "3. If its namespace is non-null and its namespace prefix is prefix, then return
+ // namespace."
if element.namespace() != &ns!() &&
element.prefix().as_ref().map(|p| &**p) == prefix.as_ref().map(|p| &**p)
{
return element.namespace().clone();
}
- // Step 2.
+ // "4. If it has an attribute whose namespace is the XMLNS namespace, namespace prefix
+ // is "xmlns", and local name is prefix, or if prefix is null and it has an attribute
+ // whose namespace is the XMLNS namespace, namespace prefix is null, and local name is
+ // "xmlns", then return its value if it is not the empty string, and null otherwise."
let attr = ref_filter_map(self.attrs(), |attrs| {
attrs.iter().find(|attr| {
if attr.namespace() != &ns!(xmlns) {