mirror of
https://github.com/servo/servo.git
synced 2025-07-22 06:43:40 +01:00
Add check for valid custom element name in element::attach_shadow (#34749)
* Add valid custom element name check Signed-off-by: stevennovaryo <steven.novaryo@gmail.com> * Update wpt test expectation Signed-off-by: stevennovaryo <steven.novaryo@gmail.com> --------- Signed-off-by: stevennovaryo <steven.novaryo@gmail.com>
This commit is contained in:
parent
ac372cf205
commit
d8b7195c75
13 changed files with 70 additions and 49 deletions
|
@ -1318,7 +1318,8 @@ fn is_potential_custom_element_char(c: char) -> bool {
|
||||||
('\u{37F}'..='\u{1FFF}').contains(&c) ||
|
('\u{37F}'..='\u{1FFF}').contains(&c) ||
|
||||||
('\u{200C}'..='\u{200D}').contains(&c) ||
|
('\u{200C}'..='\u{200D}').contains(&c) ||
|
||||||
('\u{203F}'..='\u{2040}').contains(&c) ||
|
('\u{203F}'..='\u{2040}').contains(&c) ||
|
||||||
('\u{2070}'..='\u{2FEF}').contains(&c) ||
|
('\u{2070}'..='\u{218F}').contains(&c) ||
|
||||||
|
('\u{2C00}'..='\u{2FEF}').contains(&c) ||
|
||||||
('\u{3001}'..='\u{D7FF}').contains(&c) ||
|
('\u{3001}'..='\u{D7FF}').contains(&c) ||
|
||||||
('\u{F900}'..='\u{FDCF}').contains(&c) ||
|
('\u{F900}'..='\u{FDCF}').contains(&c) ||
|
||||||
('\u{FDF0}'..='\u{FFFD}').contains(&c) ||
|
('\u{FDF0}'..='\u{FFFD}').contains(&c) ||
|
||||||
|
|
|
@ -62,6 +62,7 @@ use xml5ever::serialize::TraversalScope::{
|
||||||
ChildrenOnly as XmlChildrenOnly, IncludeNode as XmlIncludeNode,
|
ChildrenOnly as XmlChildrenOnly, IncludeNode as XmlIncludeNode,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use super::customelementregistry::is_valid_custom_element_name;
|
||||||
use super::htmltablecolelement::{HTMLTableColElement, HTMLTableColElementLayoutHelpers};
|
use super::htmltablecolelement::{HTMLTableColElement, HTMLTableColElementLayoutHelpers};
|
||||||
use crate::dom::activation::Activatable;
|
use crate::dom::activation::Activatable;
|
||||||
use crate::dom::attr::{Attr, AttrHelpersForLayout};
|
use crate::dom::attr::{Attr, AttrHelpersForLayout};
|
||||||
|
@ -511,35 +512,24 @@ impl Element {
|
||||||
clonable: bool,
|
clonable: bool,
|
||||||
) -> Fallible<DomRoot<ShadowRoot>> {
|
) -> Fallible<DomRoot<ShadowRoot>> {
|
||||||
// Step 1.
|
// Step 1.
|
||||||
|
// If element’s namespace is not the HTML namespace,
|
||||||
|
// then throw a "NotSupportedError" DOMException.
|
||||||
if self.namespace != ns!(html) {
|
if self.namespace != ns!(html) {
|
||||||
return Err(Error::NotSupported);
|
return Err(Error::NotSupported);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 2.
|
// Step 2.
|
||||||
|
// If element’s local name is not a valid shadow host name,
|
||||||
|
// then throw a "NotSupportedError" DOMException.
|
||||||
|
if !is_valid_shadow_host_name(self.local_name()) {
|
||||||
match self.local_name() {
|
match self.local_name() {
|
||||||
&local_name!("article") |
|
|
||||||
&local_name!("aside") |
|
|
||||||
&local_name!("blockquote") |
|
|
||||||
&local_name!("body") |
|
|
||||||
&local_name!("div") |
|
|
||||||
&local_name!("footer") |
|
|
||||||
&local_name!("h1") |
|
|
||||||
&local_name!("h2") |
|
|
||||||
&local_name!("h3") |
|
|
||||||
&local_name!("h4") |
|
|
||||||
&local_name!("h5") |
|
|
||||||
&local_name!("h6") |
|
|
||||||
&local_name!("header") |
|
|
||||||
&local_name!("main") |
|
|
||||||
&local_name!("nav") |
|
|
||||||
&local_name!("p") |
|
|
||||||
&local_name!("section") |
|
|
||||||
&local_name!("span") => {},
|
|
||||||
&local_name!("video") | &local_name!("audio")
|
&local_name!("video") | &local_name!("audio")
|
||||||
if is_ua_widget == IsUserAgentWidget::Yes => {},
|
if is_ua_widget == IsUserAgentWidget::Yes => {},
|
||||||
_ => return Err(Error::NotSupported),
|
_ => return Err(Error::NotSupported),
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Update the following steps to align with the newer spec.
|
||||||
// Step 3.
|
// Step 3.
|
||||||
if self.is_shadow_host() {
|
if self.is_shadow_host() {
|
||||||
return Err(Error::InvalidState);
|
return Err(Error::InvalidState);
|
||||||
|
@ -614,6 +604,40 @@ impl Element {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <https://dom.spec.whatwg.org/#valid-shadow-host-name>
|
||||||
|
#[inline]
|
||||||
|
pub fn is_valid_shadow_host_name(name: &LocalName) -> bool {
|
||||||
|
// > A valid shadow host name is:
|
||||||
|
// > - a valid custom element name
|
||||||
|
if is_valid_custom_element_name(name) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// > - "article", "aside", "blockquote", "body", "div", "footer", "h1", "h2", "h3",
|
||||||
|
// > "h4", "h5", "h6", "header", "main", "nav", "p", "section", or "span"
|
||||||
|
matches!(
|
||||||
|
name,
|
||||||
|
&local_name!("article") |
|
||||||
|
&local_name!("aside") |
|
||||||
|
&local_name!("blockquote") |
|
||||||
|
&local_name!("body") |
|
||||||
|
&local_name!("div") |
|
||||||
|
&local_name!("footer") |
|
||||||
|
&local_name!("h1") |
|
||||||
|
&local_name!("h2") |
|
||||||
|
&local_name!("h3") |
|
||||||
|
&local_name!("h4") |
|
||||||
|
&local_name!("h5") |
|
||||||
|
&local_name!("h6") |
|
||||||
|
&local_name!("header") |
|
||||||
|
&local_name!("main") |
|
||||||
|
&local_name!("nav") |
|
||||||
|
&local_name!("p") |
|
||||||
|
&local_name!("section") |
|
||||||
|
&local_name!("span")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_attr_for_layout<'dom>(
|
pub fn get_attr_for_layout<'dom>(
|
||||||
elem: LayoutDom<'dom, Element>,
|
elem: LayoutDom<'dom, Element>,
|
||||||
|
|
|
@ -1,2 +1,6 @@
|
||||||
[part-dir.html]
|
[part-dir.html]
|
||||||
expected: ERROR
|
[::part():dir() invalidation]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[::part():dir() invalidation from setAttribute]
|
||||||
|
expected: FAIL
|
||||||
|
|
|
@ -1,2 +1,6 @@
|
||||||
[part-lang.html]
|
[part-lang.html]
|
||||||
expected: ERROR
|
[::part():lang() invalidation]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[::part():lang() invalidation from setAttribute]
|
||||||
|
expected: FAIL
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
[ElementInternals-validation.html]
|
[ElementInternals-validation.html]
|
||||||
["anchor" argument of setValidity()]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Custom control affects :valid :invalid for FORM and FIELDSET]
|
[Custom control affects :valid :invalid for FORM and FIELDSET]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
[disabled-delegatesFocus.html]
|
[disabled-delegatesFocus.html]
|
||||||
expected: ERROR
|
[Focus events fire on disabled form-associated custom elements with delegatesFocus]
|
||||||
|
expected: FAIL
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
[slotchange-events.html]
|
[slotchange-events.html]
|
||||||
expected: ERROR
|
|
||||||
[Moving default content into a slot fires 'slotchange' event]
|
[Moving default content into a slot fires 'slotchange' event]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
[translate-inherit-no-parent-element.html]
|
|
||||||
[ShadowRoot parent node whose shadow host has translate=yes]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[ShadowRoot parent node whose shadow host has translate=no]
|
|
||||||
expected: FAIL
|
|
|
@ -1,4 +1,5 @@
|
||||||
[DocumentOrShadowRoot-prototype-elementFromPoint.html]
|
[DocumentOrShadowRoot-prototype-elementFromPoint.html]
|
||||||
|
expected: CRASH
|
||||||
[document.elementFromPoint and shadow.ElementFromPoint must return the shadow host of the hit-tested text node when the hit-tested text node is a direct child of the root and the host has display: inline]
|
[document.elementFromPoint and shadow.ElementFromPoint must return the shadow host of the hit-tested text node when the hit-tested text node is a direct child of the root and the host has display: inline]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,6 @@
|
||||||
[Element-interface-attachShadow-custom-element.html]
|
[Element-interface-attachShadow-custom-element.html]
|
||||||
[Element.attachShadow must create an instance of ShadowRoot for autonomous custom elements]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Element.attachShadow must create an instance of ShadowRoot for undefined autonomous custom elements]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Element.attachShadow for an autonomous custom element with disabledFeatures=["shadow"\] should throw a NotSupportedError]
|
[Element.attachShadow for an autonomous custom element with disabledFeatures=["shadow"\] should throw a NotSupportedError]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[Element.attachShadow for a customized built-in element with disabledFeatures=["shadow"\] should throw a NotSupportedError]
|
[Element.attachShadow for a customized built-in element with disabledFeatures=["shadow"\] should throw a NotSupportedError]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[Element.attachShadow for a custom element with disabledFeatures=["SHADOW"\] should not throw a NotSupportedError]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
[MouseEvent-prototype-offsetX-offsetY.html]
|
[MouseEvent-prototype-offsetX-offsetY.html]
|
||||||
expected: ERROR
|
expected: CRASH
|
||||||
[MouseEvent's offsetX and offsetY attributes must be relative to the target.]
|
[MouseEvent's offsetX and offsetY attributes must be relative to the target.]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
|
@ -1,2 +1,6 @@
|
||||||
[innerHTML-setter.xhtml]
|
[innerHTML-setter.xhtml]
|
||||||
expected: ERROR
|
[InnerHTML behavior on custom element in default 'foo' namespace]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[InnerHTML behavior with prefixes on custom element]
|
||||||
|
expected: FAIL
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
[slotchange-customelements.html]
|
[slotchange-customelements.html]
|
||||||
expected: ERROR
|
[slotchange must fire on initialization of custom elements with slotted children]
|
||||||
|
expected: FAIL
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue