mirror of
https://github.com/servo/servo.git
synced 2025-07-15 19:33:46 +01:00
script: Update name validation for attribute, element, and doctype (#37747)
A recent update in the spec (https://github.com/whatwg/dom/pull/1079) introduced new rules for name validation of attribute, element, and doctype. This PR implements the new name validation rules in `components/script/dom/bindings/domname.rs`. The old XML name validation rules are not fully removed because there remains a few usage of it in `ProcessingInstructions` and `xpath`. Testing: Covered by WPT tests Fixes: #37746 --------- Signed-off-by: minghuaw <michael.wu1107@gmail.com> Signed-off-by: Minghua Wu <michael.wu1107@gmail.com> Co-authored-by: Xiaocheng Hu <xiaochengh.work@gmail.com>
This commit is contained in:
parent
e14556959d
commit
5b507dc871
17 changed files with 380 additions and 872 deletions
|
@ -4,6 +4,7 @@
|
|||
|
||||
use dom_struct::dom_struct;
|
||||
use html5ever::{local_name, ns};
|
||||
use script_bindings::error::Error;
|
||||
use script_traits::DocumentActivity;
|
||||
|
||||
use crate::document_loader::DocumentLoader;
|
||||
|
@ -13,14 +14,12 @@ use crate::dom::bindings::codegen::Bindings::DocumentBinding::{
|
|||
};
|
||||
use crate::dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
||||
use crate::dom::bindings::codegen::UnionTypes::StringOrElementCreationOptions;
|
||||
use crate::dom::bindings::domname::{is_valid_doctype_name, namespace_from_domstring};
|
||||
use crate::dom::bindings::error::Fallible;
|
||||
use crate::dom::bindings::inheritance::Castable;
|
||||
use crate::dom::bindings::reflector::{Reflector, reflect_dom_object};
|
||||
use crate::dom::bindings::root::{Dom, DomRoot};
|
||||
use crate::dom::bindings::str::DOMString;
|
||||
use crate::dom::bindings::xmlname::{
|
||||
namespace_from_domstring, validate_and_extract_qualified_name,
|
||||
};
|
||||
use crate::dom::document::{Document, DocumentSource, HasBrowsingContext, IsHTMLDocument};
|
||||
use crate::dom::documenttype::DocumentType;
|
||||
use crate::dom::htmlbodyelement::HTMLBodyElement;
|
||||
|
@ -58,6 +57,7 @@ impl DOMImplementation {
|
|||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#domimplementation
|
||||
#[allow(non_snake_case)]
|
||||
impl DOMImplementationMethods<crate::DomTypeHolder> for DOMImplementation {
|
||||
/// <https://dom.spec.whatwg.org/#dom-domimplementation-createdocumenttype>
|
||||
fn CreateDocumentType(
|
||||
|
@ -67,8 +67,12 @@ impl DOMImplementationMethods<crate::DomTypeHolder> for DOMImplementation {
|
|||
sysid: DOMString,
|
||||
can_gc: CanGc,
|
||||
) -> Fallible<DomRoot<DocumentType>> {
|
||||
// Step 1. Validate qualifiedName.
|
||||
validate_and_extract_qualified_name(&qualified_name)?;
|
||||
// Step 1. If name is not a valid doctype name, then throw an
|
||||
// "InvalidCharacterError" DOMException.
|
||||
if !is_valid_doctype_name(&qualified_name) {
|
||||
debug!("Not a valid doctype name");
|
||||
return Err(Error::InvalidCharacter);
|
||||
}
|
||||
|
||||
Ok(DocumentType::new(
|
||||
qualified_name,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue