diff --git a/html5ever/src/serialize/mod.rs b/html5ever/src/serialize/mod.rs index 7cab15b9..752ae302 100644 --- a/html5ever/src/serialize/mod.rs +++ b/html5ever/src/serialize/mod.rs @@ -284,6 +284,6 @@ impl Serializer for HtmlSerializer { self.writer.write_all(target.as_bytes())?; self.writer.write_all(b" ")?; self.writer.write_all(data.as_bytes())?; - self.writer.write_all(b">") + self.writer.write_all(b"?>") } } diff --git a/html5ever/src/tokenizer/interface.rs b/html5ever/src/tokenizer/interface.rs index b1436a71..14e1f6a1 100644 --- a/html5ever/src/tokenizer/interface.rs +++ b/html5ever/src/tokenizer/interface.rs @@ -16,7 +16,9 @@ use crate::LocalName; use std::borrow::Cow; pub use self::TagKind::{EndTag, StartTag}; -pub use self::Token::{CharacterTokens, CommentToken, DoctypeToken, TagToken}; +pub use self::Token::{ + CharacterTokens, CommentToken, DoctypeToken, ProcessingInstructionToken, TagToken, +}; pub use self::Token::{EOFToken, NullCharacterToken, ParseError}; /// A `DOCTYPE` token. @@ -79,6 +81,13 @@ impl Tag { } } +/// A processing instruction token. +#[derive(PartialEq, Eq, Clone, Debug, Default)] +pub struct ProcessingInstruction { + pub target: StrTendril, + pub data: StrTendril, +} + #[derive(PartialEq, Eq, Debug)] pub enum Token { /// A DOCTYPE declaration like `` @@ -87,6 +96,8 @@ pub enum Token { TagToken(Tag), /// A comment like ``. CommentToken(StrTendril), + /// A processing instruction like ``. + ProcessingInstructionToken(ProcessingInstruction), /// A sequence of characters. CharacterTokens(StrTendril), /// A `U+0000 NULL` character in the input. diff --git a/html5ever/src/tokenizer/mod.rs b/html5ever/src/tokenizer/mod.rs index b388fe22..08c0ca5b 100644 --- a/html5ever/src/tokenizer/mod.rs +++ b/html5ever/src/tokenizer/mod.rs @@ -10,8 +10,10 @@ //! The HTML5 tokenizer. pub use self::interface::{CharacterTokens, EOFToken, NullCharacterToken, ParseError}; -pub use self::interface::{CommentToken, DoctypeToken, TagToken, Token}; -pub use self::interface::{Doctype, EndTag, StartTag, Tag, TagKind}; +pub use self::interface::{ + CommentToken, DoctypeToken, ProcessingInstructionToken, TagToken, Token, +}; +pub use self::interface::{Doctype, EndTag, ProcessingInstruction, StartTag, Tag, TagKind}; pub use self::interface::{TokenSink, TokenSinkResult}; use self::states::AttrValueKind::*; @@ -167,6 +169,9 @@ pub struct Tokenizer { /// Current doctype token. current_doctype: RefCell, + /// Current processing instruction token + current_processing_instruction: RefCell, + /// Last start tag name, for use in checking "appropriate end tag". last_start_tag_name: RefCell>, @@ -211,6 +216,7 @@ impl Tokenizer { current_attr_value: RefCell::new(StrTendril::new()), current_comment: RefCell::new(StrTendril::new()), current_doctype: RefCell::new(Doctype::default()), + current_processing_instruction: RefCell::new(ProcessingInstruction::default()), last_start_tag_name: RefCell::new(start_tag_name), temp_buf: RefCell::new(StrTendril::new()), state_profile: RefCell::new(BTreeMap::new()), @@ -625,6 +631,21 @@ impl Tokenizer { fn emit_error(&self, error: Cow<'static, str>) { self.process_token_and_continue(ParseError(error)); } + + fn convert_to_comment(&self) { + let mut comment = self.current_comment.borrow_mut(); + comment.clear(); + comment.push_char('?'); + // The spec doesn't specify what should happen to the temporary buffer after conversion, but + // nothing uses it afterwards so it should be fine to clear it + comment.push_tendril(&mem::take(&mut *self.temp_buf.borrow_mut())); + } + + fn emit_current_processing_instruction(&self) { + self.process_token_and_continue(ProcessingInstructionToken( + self.current_processing_instruction.take(), + )); + } } //§ END @@ -940,8 +961,7 @@ impl Tokenizer { '?' => { // Set the temporary buffer to the empty string. // Switch to the processing instruction open state. - self.bad_char_error(); - go!(self: clear_comment; reconsume BogusComment) + go!(self: clear_temp; to State::ProcessingInstructionOpen); }, // ↪ Anything else _ => { @@ -2654,7 +2674,148 @@ impl Tokenizer { }, } }, - // TODO: What about the processing-instruction related states? + + // https://html.spec.whatwg.org/#processing-instruction-open-state + states::ProcessingInstructionOpen => loop { + match get_char!(self, input) { + // ↪ ASCII alpha + // ↪ U+005F LOW LINE (_) + character if character.is_ascii_alphabetic() || character == '_' => { + // Reconsume in the processing instruction target state. + go!(self: reconsume State::ProcessingInstructionTarget); + }, + // ↪ Anything else + _ => { + // This is an invalid-first-character-of-processing-instruction-target parse error. + // Convert the temporary buffer to a comment. Reconsume in the bogus comment state. + self.bad_char_error(); + self.convert_to_comment(); + go!(self: reconsume BogusComment); + }, + } + }, + + // https://html.spec.whatwg.org/#processing-instruction-target-state + states::ProcessingInstructionTarget => loop { + match get_char!(self, input) { + // ↪ U+0009 CHARACTER TABULATION (tab) + // ↪ U+000A LINE FEED (LF) + // ↪ U+000C FORM FEED (FF) + // ↪ U+0020 SPACE + // ↪ U+003F QUESTION MARK (?) + // ↪ U+003E GREATER-THAN SIGN (>) + '\t' | '\n' | '\x0C' | ' ' | '?' | '>' => { + // Let target be the concatenation of the code points in the temporary buffer, in the order they were added to the buffer. + let is_xml_or_xml_stylesheet = { + let target = self.temp_buf.borrow(); + target.eq_ignore_ascii_case("xml") + || target.eq_ignore_ascii_case("xml-stylesheet") + }; + // If target is an ASCII case-insensitive match for "xml" or "xml-stylesheet": + if is_xml_or_xml_stylesheet { + // This is a disallowed-processing-instruction-target parse error. + // Convert the temporary buffer to a comment. + // Reconsume in the bogus comment state. + self.emit_error(Borrowed("Disallowed processing instruction target")); + self.convert_to_comment(); + go!(self: reconsume BogusComment); + } else { + let target = self.temp_buf.take(); + // Create a processing instruction token whose target is target and data is the empty string. + // Reconsume in the after processing instruction target state. + *self.current_processing_instruction.borrow_mut() = + ProcessingInstruction { + target, + data: Default::default(), + }; + go!(self: reconsume AfterProcessingInstructionTarget); + } + }, + // ↪ ASCII alphanumeric + // ↪ U+002D HYPHEN-MINUS (-) + // ↪ U+005F LOW LINE (_) + character + if character.is_ascii_alphanumeric() + || character == '-' + || character == '_' => + { + // Append the current input character to the temporary buffer. + go!(self: push_temp character); + }, + // ↪ Anything else + _ => { + // This is an invalid-processing-instruction-target parse error. + // Convert the temporary buffer to a comment. Reconsume in the bogus comment state. + self.bad_char_error(); + self.convert_to_comment(); + go!(self: reconsume BogusComment); + }, + } + }, + + // https://html.spec.whatwg.org/#after-processing-instruction-target-state + states::AfterProcessingInstructionTarget => loop { + match get_char!(self, input) { + // ↪ U+0009 CHARACTER TABULATION (tab) + // ↪ U+000A LINE FEED (LF) + // ↪ U+000C FORM FEED (FF) + // ↪ U+0020 SPACE + '\t' | '\n' | '\x0C' | ' ' => { + // Ignore the character. + }, + // ↪ Anything else + _ => { + // Reconsume in the processing instruction data state. + go!(self: reconsume ProcessingInstructionData); + }, + } + }, + + // https://html.spec.whatwg.org/#processing-instruction-data-state + states::ProcessingInstructionData => loop { + match get_char!(self, input) { + // ↪ U+003F QUESTION MARK (?) + '?' => { + // Switch to the processing instruction questionable state. + go!(self: to State::ProcessingInstructionQuestionable) + }, + // ↪ U+003E GREATER-THAN SIGN (>) + '>' => { + // Switch to the data state. Emit the current processing instruction token. + self.emit_current_processing_instruction(); + go!(self: to State::Data) + }, + // ↪ Anything else + character => { + // Append the current input character to the current processing instruction token's data. + self.current_processing_instruction + .borrow_mut() + .data + .push_char(character); + }, + } + }, + + // https://html.spec.whatwg.org/#processing-instruction-questionable-state + states::ProcessingInstructionQuestionable => loop { + match get_char!(self, input) { + // ↪ U+003E GREATER-THAN SIGN (>) + '>' => { + // Switch to the data state. Emit the current processing instruction token. + self.emit_current_processing_instruction(); + go!(self: to State::Data) + }, + // ↪ Anything else + _ => { + // Append U+003F (?) to the current processing instruction token's data. Reconsume in the processing instruction data state. + self.current_processing_instruction + .borrow_mut() + .data + .push_char('?'); + go!(self: reconsume ProcessingInstructionData); + }, + } + }, //§ END } } @@ -2775,7 +2936,12 @@ impl Tokenizer { | states::AfterAttributeValueQuoted | states::SelfClosingStartTag | states::ScriptDataEscapedDash(_) - | states::ScriptDataEscapedDashDash(_) => { + | states::ScriptDataEscapedDashDash(_) + | states::ProcessingInstructionOpen + | states::ProcessingInstructionTarget + | states::AfterProcessingInstructionTarget + | states::ProcessingInstructionData + | states::ProcessingInstructionQuestionable => { self.bad_eof_error(); go!(self: to State::Data) }, diff --git a/html5ever/src/tokenizer/states.rs b/html5ever/src/tokenizer/states.rs index 5a32f7d3..89a2d80d 100644 --- a/html5ever/src/tokenizer/states.rs +++ b/html5ever/src/tokenizer/states.rs @@ -128,4 +128,14 @@ pub enum State { CdataSectionBracket, /// CdataSectionEnd, + /// + ProcessingInstructionOpen, + /// + ProcessingInstructionTarget, + /// + AfterProcessingInstructionTarget, + /// + ProcessingInstructionData, + /// + ProcessingInstructionQuestionable, } diff --git a/html5ever/src/tree_builder/mod.rs b/html5ever/src/tree_builder/mod.rs index 803a398e..ca19b6ad 100644 --- a/html5ever/src/tree_builder/mod.rs +++ b/html5ever/src/tree_builder/mod.rs @@ -526,6 +526,9 @@ where tokenizer::TagToken(x) => Token::Tag(x), tokenizer::CommentToken(x) => Token::Comment(x), + tokenizer::ProcessingInstructionToken(x) => { + Token::ProcessingInstruction(x.target, x.data) + }, tokenizer::NullCharacterToken => Token::NullCharacter, tokenizer::EOFToken => Token::Eof, @@ -1342,6 +1345,40 @@ where ProcessResult::Done } + fn append_processing_instruction( + &self, + target: StrTendril, + data: StrTendril, + ) -> ProcessResult { + let processing_instruction = self.sink.create_pi(target, data); + self.insert_appropriately(AppendNode(processing_instruction), None); + ProcessResult::Done + } + + fn append_processing_instruction_to_doc( + &self, + target: StrTendril, + data: StrTendril, + ) -> ProcessResult { + let processing_instruction = self.sink.create_pi(target, data); + self.sink + .append(&self.doc_handle, AppendNode(processing_instruction)); + ProcessResult::Done + } + + fn append_processing_instruction_to_html( + &self, + target: StrTendril, + data: StrTendril, + ) -> ProcessResult { + let open_elements = self.open_elems.borrow(); + let element_target = html_elem(&open_elements); + let processing_instruction = self.sink.create_pi(target, data); + self.sink + .append(element_target, AppendNode(processing_instruction)); + ProcessResult::Done + } + //§ creating-and-inserting-nodes fn create_root(&self, attrs: Vec) { let elem = create_element( diff --git a/html5ever/src/tree_builder/rules.rs b/html5ever/src/tree_builder/rules.rs index a7b3e24a..5cb14c07 100644 --- a/html5ever/src/tree_builder/rules.rs +++ b/html5ever/src/tree_builder/rules.rs @@ -104,6 +104,9 @@ where }, Token::Characters(SplitStatus::Whitespace, _) => ProcessResult::Done, Token::Comment(text) => self.append_comment_to_doc(text), + Token::ProcessingInstruction(target, data) => { + self.append_processing_instruction_to_doc(target, data) + }, token => { if !self.opts.iframe_srcdoc { self.unexpected(&token); @@ -124,6 +127,10 @@ where match token { Token::Comment(text) => self.append_comment_to_doc(text), + Token::ProcessingInstruction(target, data) => { + self.append_processing_instruction_to_doc(target, data) + }, + Token::Characters(SplitStatus::NotSplit, text) => { ProcessResult::SplitWhitespace(text) }, @@ -155,6 +162,9 @@ where }, Token::Characters(SplitStatus::Whitespace, _) => ProcessResult::Done, Token::Comment(text) => self.append_comment(text), + Token::ProcessingInstruction(target, data) => { + self.append_processing_instruction(target, data) + }, Token::Tag(tag!()) => self.step(InsertionMode::InBody, token), @@ -186,6 +196,9 @@ where }, Token::Characters(SplitStatus::Whitespace, text) => self.append_text(text), Token::Comment(text) => self.append_comment(text), + Token::ProcessingInstruction(target, data) => { + self.append_processing_instruction(target, data) + }, Token::Tag(tag!()) => self.step(InsertionMode::InBody, token), @@ -338,6 +351,7 @@ where }, Token::Comment(_) => self.step(InsertionMode::InHead, token), + Token::ProcessingInstruction(_, _) => self.step(InsertionMode::InHead, token), Token::Tag( tag!( | | | | | <style>), @@ -365,6 +379,9 @@ where }, Token::Characters(SplitStatus::Whitespace, text) => self.append_text(text), Token::Comment(text) => self.append_comment(text), + Token::ProcessingInstruction(target, data) => { + self.append_processing_instruction(target, data) + }, Token::Tag(tag!(<html>)) => self.step(InsertionMode::InBody, token), @@ -424,6 +441,10 @@ where Token::Comment(text) => self.append_comment(text), + Token::ProcessingInstruction(target, data) => { + self.append_processing_instruction(target, data) + }, + Token::Tag(tag @ tag!(<html>)) => { self.unexpected(&tag); if !self.in_html_elem_named(local_name!("template")) { @@ -1039,6 +1060,10 @@ where Token::Comment(text) => self.append_comment(text), + Token::ProcessingInstruction(target, data) => { + self.append_processing_instruction(target, data) + }, + Token::Tag(tag @ tag!(<caption>)) => { self.pop_until_current(table_scope); self.active_formatting @@ -1212,6 +1237,9 @@ where }, Token::Characters(SplitStatus::Whitespace, text) => self.append_text(text), Token::Comment(text) => self.append_comment(text), + Token::ProcessingInstruction(target, data) => { + self.append_processing_instruction(target, data) + }, Token::Tag(tag!(<html>)) => self.step(InsertionMode::InBody, token), @@ -1414,6 +1442,7 @@ where InsertionMode::InTemplate => match token { Token::Characters(_, _) => self.step(InsertionMode::InBody, token), Token::Comment(_) => self.step(InsertionMode::InBody, token), + Token::ProcessingInstruction(_, _) => self.step(InsertionMode::InBody, token), Token::Tag( tag!(<base> | <basefont> | <bgsound> | <link> | <meta> | <noframes> | <script> | @@ -1482,6 +1511,9 @@ where self.step(InsertionMode::InBody, token) }, Token::Comment(text) => self.append_comment_to_html(text), + Token::ProcessingInstruction(target, data) => { + self.append_processing_instruction_to_html(target, data) + }, Token::Tag(tag!(<html>)) => self.step(InsertionMode::InBody, token), @@ -1510,6 +1542,9 @@ where }, Token::Characters(SplitStatus::Whitespace, text) => self.append_text(text), Token::Comment(text) => self.append_comment(text), + Token::ProcessingInstruction(target, data) => { + self.append_processing_instruction(target, data) + }, Token::Tag(tag!(<html>)) => self.step(InsertionMode::InBody, token), @@ -1556,6 +1591,9 @@ where }, Token::Characters(SplitStatus::Whitespace, text) => self.append_text(text), Token::Comment(text) => self.append_comment(text), + Token::ProcessingInstruction(target, data) => { + self.append_processing_instruction(target, data) + }, Token::Tag(tag!(<html>)) => self.step(InsertionMode::InBody, token), @@ -1581,6 +1619,9 @@ where self.step(InsertionMode::InBody, token) }, Token::Comment(text) => self.append_comment_to_doc(text), + Token::ProcessingInstruction(target, data) => { + self.append_processing_instruction_to_doc(target, data) + }, Token::Tag(tag!(<html>)) => self.step(InsertionMode::InBody, token), @@ -1602,6 +1643,9 @@ where self.step(InsertionMode::InBody, token) }, Token::Comment(text) => self.append_comment_to_doc(text), + Token::ProcessingInstruction(target, data) => { + self.append_processing_instruction_to_doc(target, data) + }, Token::Tag(tag!(<html>)) => self.step(InsertionMode::InBody, token), @@ -1632,6 +1676,10 @@ where Token::Comment(text) => self.append_comment(text), + Token::ProcessingInstruction(target, data) => { + self.append_processing_instruction(target, data) + }, + Token::Tag( tag @ tag!(<b> | <big> | <blockquote> | <body> | <br> | <center> | <code> | <dd> | <div> | <dl> | diff --git a/html5ever/src/tree_builder/types.rs b/html5ever/src/tree_builder/types.rs index 9177ff2b..a60f053b 100644 --- a/html5ever/src/tree_builder/types.rs +++ b/html5ever/src/tree_builder/types.rs @@ -74,6 +74,7 @@ pub(crate) enum SplitStatus { pub(crate) enum Token { Tag(Tag), Comment(StrTendril), + ProcessingInstruction(StrTendril, StrTendril), Characters(SplitStatus, StrTendril), NullCharacter, Eof, diff --git a/rcdom/data/test/wpt-commit.txt b/rcdom/data/test/wpt-commit.txt index a26d7459..a165562d 100644 --- a/rcdom/data/test/wpt-commit.txt +++ b/rcdom/data/test/wpt-commit.txt @@ -1 +1 @@ -31d1feb70e2d02f25ae26254caba19c8de0b56e0 +4aa56d3beafc5655fa55491169eb14845b44eab3 diff --git a/rcdom/examples/print-rcdom.rs b/rcdom/examples/print-rcdom.rs index e1d8fc68..96b06e30 100644 --- a/rcdom/examples/print-rcdom.rs +++ b/rcdom/examples/print-rcdom.rs @@ -53,7 +53,16 @@ fn walk(indent: usize, handle: &Handle) { println!(">"); }, - NodeData::ProcessingInstruction { .. } => unreachable!(), + NodeData::ProcessingInstruction { + ref target, + ref contents, + } => { + println!( + "<?{} {}?>", + target.escape_default(), + contents.escape_default() + ) + }, } for child in node.children.borrow().iter() { diff --git a/rcdom/html5lib-tests b/rcdom/html5lib-tests index f994590f..c777c408 160000 --- a/rcdom/html5lib-tests +++ b/rcdom/html5lib-tests @@ -1 +1 @@ -Subproject commit f994590f528ac8b6073665791ddb1ed85c66dfb2 +Subproject commit c777c408b61078ea2eb4acefc2535f54dbc8b28a diff --git a/rcdom/tests/html-serializer.rs b/rcdom/tests/html-serializer.rs index 176a417d..3122080e 100644 --- a/rcdom/tests/html-serializer.rs +++ b/rcdom/tests/html-serializer.rs @@ -57,6 +57,9 @@ impl Serialize for Tokens { } }, Token::CommentToken(chars) => serializer.write_comment(chars)?, + Token::ProcessingInstructionToken(pi) => { + serializer.write_processing_instruction(&pi.target, &pi.data)? + }, Token::CharacterTokens(chars) => serializer.write_text(chars)?, Token::NullCharacterToken | &Token::EOFToken => {}, Token::ParseError(e) => println!("parse error: {e:#?}"), @@ -243,6 +246,24 @@ test!(attr_ns_2, r#"<svg xmlns:foo="bleh"></svg>"#); test!(attr_ns_3, r#"<svg xmlns:xlink="bleh"></svg>"#); test!(attr_ns_4, r#"<svg xlink:href="bleh"></svg>"#); +test!(processing_instruction_1, r#"<?target>"#, r#"<?target ?>"#); + +test!(processing_instruction_2, r#"<?target?>"#, r#"<?target ?>"#); + +test!(processing_instruction_3, r#"<?target >"#, r#"<?target ?>"#); + +test!( + processing_instruction_4, + r#"<?target ??>"#, + r#"<?target ??>"# +); + +test!( + processing_instruction_5, + r#"<?target ?>"#, + r#"<?target ?>"# +); + test_no_parse!(malformed_tokens, r#"foo</div><div>"#); #[test] diff --git a/rcdom/tests/html-tokenizer.rs b/rcdom/tests/html-tokenizer.rs index 7ac8767a..c24694a6 100644 --- a/rcdom/tests/html-tokenizer.rs +++ b/rcdom/tests/html-tokenizer.rs @@ -16,8 +16,10 @@ use html5ever::tokenizer::states::{ }; use html5ever::tokenizer::BufferQueue; use html5ever::tokenizer::{CharacterTokens, EOFToken, NullCharacterToken, ParseError}; -use html5ever::tokenizer::{CommentToken, DoctypeToken, TagToken, Token}; -use html5ever::tokenizer::{Doctype, EndTag, StartTag, Tag}; +use html5ever::tokenizer::{ + CommentToken, DoctypeToken, ProcessingInstructionToken, TagToken, Token, +}; +use html5ever::tokenizer::{Doctype, EndTag, ProcessingInstruction, StartTag, Tag}; use html5ever::tokenizer::{TokenSink, TokenSinkResult, Tokenizer, TokenizerOpts}; use html5ever::TokenizerResult; use html5ever::{ns, Attribute, LocalName, QualName}; @@ -264,6 +266,11 @@ fn json_to_token(js: &Value) -> Token { "Comment" => CommentToken(args[0].get_tendril()), + "ProcessingInstruction" => ProcessingInstructionToken(ProcessingInstruction { + target: args[0].get_tendril(), + data: args[1].get_tendril(), + }), + "Character" => CharacterTokens(args[0].get_tendril()), // We don't need to produce NullCharacterToken because diff --git a/rcdom/tests/html-tree-builder.rs b/rcdom/tests/html-tree-builder.rs index 7473d4a9..0227d32b 100644 --- a/rcdom/tests/html-tree-builder.rs +++ b/rcdom/tests/html-tree-builder.rs @@ -35,6 +35,7 @@ fn parse_tests<It: Iterator<Item = String>>(mut lines: It) -> Vec<HashMap<String let mut test = HashMap::new(); let mut key: Option<String> = None; let mut val = String::new(); + let mut started_with_description = false; macro_rules! finish_val ( () => ( match key.take() { @@ -58,7 +59,13 @@ fn parse_tests<It: Iterator<Item = String>>(mut lines: It) -> Vec<HashMap<String if let Some(rest) = line.strip_prefix('#') { finish_val!(); if line == "#data" { + if !started_with_description { + finish_test!(); + } + started_with_description = false; + } else if line == "#description" { finish_test!(); + started_with_description = true; } key = Some(rest.to_owned()); } else { @@ -138,7 +145,16 @@ fn serialize(buf: &mut String, indent: usize, handle: Handle) { } }, - NodeData::ProcessingInstruction { .. } => unreachable!(), + NodeData::ProcessingInstruction { + ref target, + ref contents, + } => { + buf.push_str("<?"); + buf.push_str(target); + buf.push(' '); + buf.push_str(contents); + buf.push_str("?>\n"); + }, } for child in node.children.borrow().iter() { @@ -196,14 +212,22 @@ fn make_test_desc_with_scripting_flag( .to_string() }; + let skip = ignores.contains(name); + let mut name = name.to_owned(); + + let description = fields.get("description"); + + if let Some(description) = description { + name.push_str(": "); + name.push_str(description.trim_end_matches('\n')); + } + let mut data = expect_field("data"); data.pop(); let expected = expect_field("document").trim_end_matches('\n').to_string(); let context = fields .get("document-fragment") .map(|field| context_name(field.trim_end_matches('\n'))); - let skip = ignores.contains(name); - let mut name = name.to_owned(); if scripting_enabled { name.push_str(" (scripting enabled)"); } else { diff --git a/rcdom/wpt-tree-construction-tests/README.md b/rcdom/wpt-tree-construction-tests/README.md new file mode 100644 index 00000000..0f4be3b4 --- /dev/null +++ b/rcdom/wpt-tree-construction-tests/README.md @@ -0,0 +1,112 @@ +Tree Construction Tests +======================= + +Each file containing tree construction tests consists of any number of +tests separated by two newlines (LF) and a single newline before the end +of the file. For instance: + + [TEST]LF + LF + [TEST]LF + LF + [TEST]LF + +Where [TEST] is the following format: + +Each test \*may\* begin with a string "\#description" followed by a +newline (LF). All subsequent lines until a line that says "\#data" are +the test description and \*should\* be passed to the test harness to +supplement the test's name. + +Each test must either begin with "\#description" (see above) or begin +with a string "\#data" followed by a newline (LF). All subsequent lines +until a line that says "\#errors" are the test data and must be passed +to the system being tested unchanged, except with the final newline +(on the last line) removed. + +Then there must be a line that says "\#errors". It must be followed by +one line per parse error that a conformant checker would return. It +doesn't matter what those lines are, although they can't be +"\#new-errors", "\#document-fragment", "\#document", "\#script-off", +"\#script-on", or empty, the only thing that matters is that there be +the right number of parse errors. + +Then there \*may\* be a line that says "\#new-errors", which works like +the "\#errors" section adding more errors to the expected number of +errors. + +Then there \*may\* be a line that says "\#document-fragment", which must +be followed by a newline (LF), followed by a string of characters that +indicates the context element, followed by a newline (LF). If the string +of characters starts with "svg ", the context element is in the SVG +namespace and the substring after "svg " is the local name. If the +string of characters starts with "math ", the context element is in the +MathML namespace and the substring after "math " is the local name. +Otherwise, the context element is in the HTML namespace and the string +is the local name. If this line is present the "\#data" must be parsed +using the HTML fragment parsing algorithm with the context element as +context. + +Then there \*may\* be a line that says "\#script-off" or +"\#script-on". If a line that says "\#script-off" is present, the +parser must set the scripting flag to disabled. If a line that says +"\#script-on" is present, it must set it to enabled. Otherwise, the +test should be run in both modes. + +Then there must be a line that says "\#document", which must be followed +by a dump of the tree of the parsed DOM. Each node must be represented +by a single line. Each line must start with "| ", followed by two spaces +per parent node that the node has before the root document node. + +- Element nodes must be represented by a "`<`" then the *tag name + string* "`>`", and all the attributes must be given, sorted + lexicographically by UTF-16 code unit according to their *attribute + name string*, on subsequent lines, as if they were children of the + element node. +- Attribute nodes must have the *attribute name string*, then an "=" + sign, then the attribute value in double quotes ("). +- Text nodes must be the string, in double quotes. Newlines aren't + escaped. +- Comments must be "`<`" then "`!-- `" then the data then "` -->`". +- DOCTYPEs must be "`<!DOCTYPE `" then the name then if either of the + system id or public id is non-empty a space, public id in + double-quotes, another space an the system id in double-quotes, and + then in any case "`>`". +- Processing instructions must be "`<?`", then the target, then a + space, then the data and then "`?>`". +- Template contents are represented by the string "content" with the + children below it. + +The *tag name string* is the local name prefixed by a namespace +designator. For the HTML namespace, the namespace designator is the +empty string, i.e. there's no prefix. For the SVG namespace, the +namespace designator is "svg ". For the MathML namespace, the namespace +designator is "math ". + +The *attribute name string* is the local name prefixed by a namespace +designator. For no namespace, the namespace designator is the empty +string, i.e. there's no prefix. For the XLink namespace, the namespace +designator is "xlink ". For the XML namespace, the namespace designator +is "xml ". For the XMLNS namespace, the namespace designator is "xmlns +". Note the difference between "xlink:href" which is an attribute in no +namespace with the local name "xlink:href" and "xlink href" which is an +attribute in the xlink namespace with the local name "href". + +If there is also a "\#document-fragment" the bit following "\#document" +must be a representation of the HTML fragment serialization for the +context element given by "\#document-fragment". + +For example: + + #data + <p>One<p>Two + #errors + 3: Missing document type declaration + #document + | <html> + | <head> + | <body> + | <p> + | "One" + | <p> + | "Two" diff --git a/rcdom/wpt-tree-construction-tests/adoption-agency-reparenting.js b/rcdom/wpt-tree-construction-tests/adoption-agency-reparenting.js new file mode 100644 index 00000000..434d2969 --- /dev/null +++ b/rcdom/wpt-tree-construction-tests/adoption-agency-reparenting.js @@ -0,0 +1,32 @@ +"use strict"; + +// Shared helpers for the adoption-agency-reparenting tests. + +// Compact serializer: element -> <name>[#id][children]; text -> "data". +// <script> contents are elided to keep expectations stable. +function serialize(n) { + if (n.nodeType === Node.TEXT_NODE) + return `"${n.data}"`; + if (n.nodeType !== Node.ELEMENT_NODE) + return ""; + const label = `<${n.localName}${n.id ? "#" + n.id : ""}>`; + if (n.localName === "script") + return label; + const kids = tree(n); + return kids ? `${label}[${kids}]` : label; +} + +function tree(node) { + return [...node.childNodes].map(serialize).join(""); +} + +// Parse srcdoc in an iframe (so inline scripts run during parsing) and resolve +// with the iframe once loaded. +function parseInIframe(t, srcdoc) { + const iframe = document.createElement("iframe"); + iframe.srcdoc = srcdoc; + return new Promise(resolve => { + iframe.onload = t.step_func(() => resolve(iframe)); + document.body.appendChild(iframe); + }); +} diff --git a/rcdom/wpt-tree-construction-tests/adoption02.dat b/rcdom/wpt-tree-construction-tests/adoption02.dat index e54d8033..880cb505 100644 --- a/rcdom/wpt-tree-construction-tests/adoption02.dat +++ b/rcdom/wpt-tree-construction-tests/adoption02.dat @@ -37,3 +37,36 @@ | <address> | <a> | <a> + +#data +<nobr><table><marquee></table><nobr> +#errors +(1,6): expected-doctype-but-got-start-tag +(1,22): unexpected-start-tag-implies-table-voodoo +(1,30): end-tag-too-early-named +(1,36): unexpected-start-tag-implies-end-tag +(1,36): expected-closing-tag-but-got-eof +#document +| <html> +| <head> +| <body> +| <nobr> +| <marquee> +| <table> +| <nobr> + +#data +<a><table><marquee></table><a> +#errors +(1,3): expected-doctype-but-got-start-tag +(1,19): unexpected-start-tag-implies-table-voodoo +(1,27): end-tag-too-early-named +(1,30): expected-closing-tag-but-got-eof +#document +| <html> +| <head> +| <body> +| <a> +| <marquee> +| <table> +| <a> diff --git a/rcdom/wpt-tree-construction-tests/comments01.dat b/rcdom/wpt-tree-construction-tests/comments01.dat index 4b9ff957..f9a4ece8 100644 --- a/rcdom/wpt-tree-construction-tests/comments01.dat +++ b/rcdom/wpt-tree-construction-tests/comments01.dat @@ -155,10 +155,9 @@ FOO<!-->BAZ #data <?xml version="1.0">Hi #errors -(1,1): expected-tag-name-but-got-question-mark (1,22): expected-doctype-but-got-chars #new-errors -(1:2) unexpected-question-mark-instead-of-tag-name +(1:6) disallowed-processing-instruction-target #document | <!-- ?xml version="1.0" --> | <html> @@ -169,10 +168,9 @@ FOO<!-->BAZ #data <?xml version="1.0"> #errors -(1,1): expected-tag-name-but-got-question-mark (1,20): expected-doctype-but-got-eof #new-errors -(1:2) unexpected-question-mark-instead-of-tag-name +(1:6) disallowed-processing-instruction-target #document | <!-- ?xml version="1.0" --> | <html> @@ -182,10 +180,9 @@ FOO<!-->BAZ #data <?xml version #errors -(1,1): expected-tag-name-but-got-question-mark (1,13): expected-doctype-but-got-eof #new-errors -(1:2) unexpected-question-mark-instead-of-tag-name +(1:6) disallowed-processing-instruction-target #document | <!-- ?xml version --> | <html> diff --git a/rcdom/wpt-tree-construction-tests/html5test-com.dat b/rcdom/wpt-tree-construction-tests/html5test-com.dat index 48d0bf95..d5462575 100644 --- a/rcdom/wpt-tree-construction-tests/html5test-com.dat +++ b/rcdom/wpt-tree-construction-tests/html5test-com.dat @@ -129,12 +129,9 @@ #data <?import namespace="foo" implementation="#bar"> #errors -(1,1): expected-tag-name-but-got-question-mark (1,47): expected-doctype-but-got-eof -#new-errors -(1:2) unexpected-question-mark-instead-of-tag-name #document -| <!-- ?import namespace="foo" implementation="#bar" --> +| <?import namespace="foo" implementation="#bar"?> | <html> | <head> | <body> @@ -149,6 +146,73 @@ | <head> | <body> +#data +<svg><title><![CDATA[x]]> +#errors +#document +| <html> +| <head> +| <body> +| <svg svg> +| <svg title> +| "x" + +#data +<svg><foreignobject><![CDATA[x]]> +#errors +#document +| <html> +| <head> +| <body> +| <svg svg> +| <svg foreignObject> +| "x" + +#data +<svg><foreignobject><p><![CDATA[x]]> +#errors +#document +| <html> +| <head> +| <body> +| <svg svg> +| <svg foreignObject> +| <p> +| <!-- [CDATA[x]] --> + +#data +<math><![CDATA[x]]> +#errors +#document +| <html> +| <head> +| <body> +| <math math> +| "x" + +#data +<math><mtext><![CDATA[x]]> +#errors +#document +| <html> +| <head> +| <body> +| <math math> +| <math mtext> +| "x" + +#data +<math><mtext><i><![CDATA[x]]> +#errors +#document +| <html> +| <head> +| <body> +| <math math> +| <math mtext> +| <i> +| <!-- [CDATA[x]] --> + #data <![CDATA[x]]> #errors diff --git a/rcdom/wpt-tree-construction-tests/plain-text-unsafe.dat b/rcdom/wpt-tree-construction-tests/plain-text-unsafe.dat index e904eff0..87a909f0 100644 Binary files a/rcdom/wpt-tree-construction-tests/plain-text-unsafe.dat and b/rcdom/wpt-tree-construction-tests/plain-text-unsafe.dat differ diff --git a/rcdom/wpt-tree-construction-tests/processing-instructions.dat b/rcdom/wpt-tree-construction-tests/processing-instructions.dat new file mode 100644 index 00000000..c516eab0 --- /dev/null +++ b/rcdom/wpt-tree-construction-tests/processing-instructions.dat @@ -0,0 +1,1132 @@ +#data +<body><?something> +#errors +#document +| <html> +| <head> +| <body> +| <?something ?> + +#data +<body><?something><span> +#errors +#document +| <html> +| <head> +| <body> +| <?something ?> +| <span> + +#data +<body><?something good> +#errors +#document +| <html> +| <head> +| <body> +| <?something good?> + +#data +<body><?something else is good> +#errors +#document +| <html> +| <head> +| <body> +| <?something else is good?> + +#data +<body><?one><?two> +#errors +#document +| <html> +| <head> +| <body> +| <?one ?> +| <?two ?> + +#data +<body><?a$><?b$><?good?> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?a$ --> +| <!-- ?b$ --> +| <?good ?> + +#data +<body><?hey there?> +#errors +#document +| <html> +| <head> +| <body> +| <?hey there?> + +#data +<body><?hey there?> +#errors +#document +| <html> +| <head> +| <body> +| <?hey there?> + +#data +<body><?hey?there> +#errors +#document +| <html> +| <head> +| <body> +| <?hey ?there?> + +#data +<body><?hey there=1?> +#errors +#document +| <html> +| <head> +| <body> +| <?hey there=1?> + +#data +<body><?hey +there=1?> +#errors +#document +| <html> +| <head> +| <body> +| <?hey there=1?> + +#data +<body><?hey there=1?> +#errors +#document +| <html> +| <head> +| <body> +| <?hey there=1?> + +#data +<body><?hey there=1?> +#errors +#document +| <html> +| <head> +| <body> +| <?hey there=1?> + +#data +<body><?something ? > +#errors +#document +| <html> +| <head> +| <body> +| <?something ? ?> + +#data +<body><?something x > +#errors +#document +| <html> +| <head> +| <body> +| <?something x ?> + +#data +<body><?something ?\t ??> +#errors +#document +| <html> +| <head> +| <body> +| <?something ?\t ??> + +#data +<body><?t d > ?> +#errors +#document +| <html> +| <head> +| <body> +| <?t d ?> +| " ?>" + +#data +<body><?module-handler> +#errors +#document +| <html> +| <head> +| <body> +| <?module-handler ?> + +#data +<body><?module-handler data> +#errors +#document +| <html> +| <head> +| <body> +| <?module-handler data?> + +#data +<body><?view-port> +#errors +#document +| <html> +| <head> +| <body> +| <?view-port ?> + +#data +<body><?view-port data> +#errors +#document +| <html> +| <head> +| <body> +| <?view-port data?> + +#data +<body><?config-v2> +#errors +#document +| <html> +| <head> +| <body> +| <?config-v2 ?> + +#data +<body><?config-v2 data> +#errors +#document +| <html> +| <head> +| <body> +| <?config-v2 data?> + +#data +<body><?x> +#errors +#document +| <html> +| <head> +| <body> +| <?x ?> + +#data +<body><?x data> +#errors +#document +| <html> +| <head> +| <body> +| <?x data?> + +#data +<body><?zz2op> +#errors +#document +| <html> +| <head> +| <body> +| <?zz2op ?> + +#data +<body><?zz2op data> +#errors +#document +| <html> +| <head> +| <body> +| <?zz2op data?> + +#data +<body><?xla-> +#errors +#document +| <html> +| <head> +| <body> +| <?xla- ?> + +#data +<body><?xla- data> +#errors +#document +| <html> +| <head> +| <body> +| <?xla- data?> + +#data +<body><?a-b-c> +#errors +#document +| <html> +| <head> +| <body> +| <?a-b-c ?> + +#data +<body><?a-b-c data> +#errors +#document +| <html> +| <head> +| <body> +| <?a-b-c data?> + +#data +<body><?v-123> +#errors +#document +| <html> +| <head> +| <body> +| <?v-123 ?> + +#data +<body><?v-123 data> +#errors +#document +| <html> +| <head> +| <body> +| <?v-123 data?> + +#data +<body><?a0-b1-c2> +#errors +#document +| <html> +| <head> +| <body> +| <?a0-b1-c2 ?> + +#data +<body><?a0-b1-c2 data> +#errors +#document +| <html> +| <head> +| <body> +| <?a0-b1-c2 data?> + +#data +<body><?page-404> +#errors +#document +| <html> +| <head> +| <body> +| <?page-404 ?> + +#data +<body><?page-404 data> +#errors +#document +| <html> +| <head> +| <body> +| <?page-404 data?> + +#data +<body><?r2-d2> +#errors +#document +| <html> +| <head> +| <body> +| <?r2-d2 ?> + +#data +<body><?r2-d2 data> +#errors +#document +| <html> +| <head> +| <body> +| <?r2-d2 data?> + +#data +<body><?level-99> +#errors +#document +| <html> +| <head> +| <body> +| <?level-99 ?> + +#data +<body><?level-99 data> +#errors +#document +| <html> +| <head> +| <body> +| <?level-99 data?> + +#data +<body><?UPPERCASE> +#errors +#document +| <html> +| <head> +| <body> +| <?UPPERCASE ?> + +#data +<body><?UPPERCASE data> +#errors +#document +| <html> +| <head> +| <body> +| <?UPPERCASE data?> + +#data +<body><?all-KINDS-of-CaSeS> +#errors +#document +| <html> +| <head> +| <body> +| <?all-KINDS-of-CaSeS ?> + +#data +<body><?all-KINDS-of-CaSeS data> +#errors +#document +| <html> +| <head> +| <body> +| <?all-KINDS-of-CaSeS data?> + +#data +<body><?user_name> +#errors +#document +| <html> +| <head> +| <body> +| <?user_name ?> + +#data +<body><?user_name data> +#errors +#document +| <html> +| <head> +| <body> +| <?user_name data?> + +#data +<body><?S_S-S_S> +#errors +#document +| <html> +| <head> +| <body> +| <?S_S-S_S ?> + +#data +<body><?S_S-S_S data> +#errors +#document +| <html> +| <head> +| <body> +| <?S_S-S_S data?> + +#data +<body><?b_> +#errors +#document +| <html> +| <head> +| <body> +| <?b_ ?> + +#data +<body><?b_ data> +#errors +#document +| <html> +| <head> +| <body> +| <?b_ data?> + +#data +<body><?_prefix> +#errors +#document +| <html> +| <head> +| <body> +| <?_prefix ?> + +#data +<body><?_prefix data> +#errors +#document +| <html> +| <head> +| <body> +| <?_prefix data?> + +#data +<body><?_x132> +#errors +#document +| <html> +| <head> +| <body> +| <?_x132 ?> + +#data +<body><?_x132 data> +#errors +#document +| <html> +| <head> +| <body> +| <?_x132 data?> + +#data +<body><?_-_> +#errors +#document +| <html> +| <head> +| <body> +| <?_-_ ?> + +#data +<body><?_-_ data> +#errors +#document +| <html> +| <head> +| <body> +| <?_-_ data?> + +#data +<body><?_> +#errors +#document +| <html> +| <head> +| <body> +| <?_ ?> + +#data +<body><?_ data> +#errors +#document +| <html> +| <head> +| <body> +| <?_ data?> + +#data +<body><?A----------------> +#errors +#document +| <html> +| <head> +| <body> +| <?A---------------- ?> + +#data +<body><?A---------------- data> +#errors +#document +| <html> +| <head> +| <body> +| <?A---------------- data?> + +#data +<body><?z0123456789> +#errors +#document +| <html> +| <head> +| <body> +| <?z0123456789 ?> + +#data +<body><?z0123456789 data> +#errors +#document +| <html> +| <head> +| <body> +| <?z0123456789 data?> + +#data +<body><?m-0> +#errors +#document +| <html> +| <head> +| <body> +| <?m-0 ?> + +#data +<body><?m-0 data> +#errors +#document +| <html> +| <head> +| <body> +| <?m-0 data?> + +#data +<body><?xml> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?xml --> + +#data +<body><?xml-stylesheet> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?xml-stylesheet --> + +#data +<body><?XML> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?XML --> + +#data +<body><?XML-stylesheet> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?XML-stylesheet --> + +#data +<body><?xML> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?xML --> + +#data +<body><?xml-STYLesheet> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?xml-STYLesheet --> + +#data +<body><?1st-place> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?1st-place --> + +#data +<body><?2-factor> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?2-factor --> + +#data +<body><?99-problems> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?99-problems --> + +#data +<body><?٥-star> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?٥-star --> + +#data +<body><?-prefix> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?-prefix --> + +#data +<body><?--internal> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?--internal --> + +#data +<body><?-data-> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?-data- --> + +#data +<body><?-100> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?-100 --> + +#data +<body><?·middle-dot> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?·middle-dot --> + +#data +<body><?͵greek-numeral> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?͵greek-numeral --> + +#data +<body><?́accent-start> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?́accent-start --> + +#data +<body><?price$value> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?price$value --> + +#data +<body><?user@domain> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?user@domain --> + +#data +<body><?tag#id> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?tag#id --> + +#data +<body><?a+b> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?a+b --> + +#data +<body><?100%> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?100% --> + +#data +<body><?data.v1> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?data.v1 --> + +#data +<body><?namespace:tag> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?namespace:tag --> + +#data +<body><?error!code> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?error!code --> + +#data +<body><?x=y> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?x=y --> + +#data +<body><?a<b> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?a<b --> + +#data +<body><?true&false> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?true&false --> + +#data +<body><?not|or> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?not|or --> + +#data +<body><?lit$123456789> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?lit$123456789 --> + +#data +<body><?lit$$4x> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?lit$$4x --> + +#data +<body><?🚀-launch> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?🚀-launch --> + +#data +<body><?error-⚠️> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?error-⚠️ --> + +#data +<body><?fire-🔥> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?fire-🔥 --> + +#data +<body><?v1-✅> +#errors +#document +| <html> +| <head> +| <body> +| <!-- ?v1-✅ --> + +#data +<body><?start +#errors +#document +| <html> +| <head> +| <body> + +#data +<body><?start? +#errors +#document +| <html> +| <head> +| <body> + +#data +<body><?start +#errors +#document +| <html> +| <head> +| <body> + +#data +<body><?start data +#errors +#document +| <html> +| <head> +| <body> + +#data +<body><?start ? ? +#errors +#document +| <html> +| <head> +| <body> + +#data +<body><? +#errors +#document +| <html> +| <head> +| <body> + +#data +<body><? +#errors +#document +| <html> +| <head> +| <body> +| <!-- ? --> + +#data +<div><?something></div> +#errors +#document +| <html> +| <head> +| <body> +| <div> +| <?something ?> + +#data +<div><?something good></div> +#errors +#document +| <html> +| <head> +| <body> +| <div> +| <?something good?> + +#data +<table><?something></table> +#errors +#document +| <html> +| <head> +| <body> +| <table> +| <?something ?> + +#data +<table><tr><?something></tr></table> +#errors +#document +| <html> +| <head> +| <body> +| <table> +| <tbody> +| <tr> +| <?something ?> + +#data +<script><?something></script> +#errors +#document +| <html> +| <head> +| <script> +| "<?something>" +| <body> + +#data +<style><?something></style> +#errors +#document +| <html> +| <head> +| <style> +| "<?something>" +| <body> + +#data +<?something> +#errors +#document +| <?something ?> +| <html> +| <head> +| <body> + +#data +<head><?something> +#errors +#document +| <html> +| <head> +| <?something ?> +| <body> + +#data +<html><?something><head> +#errors +#document +| <html> +| <?something ?> +| <head> +| <body> + +#data +<html><head></head><?something><body> +#errors +#document +| <html> +| <head> +| <?something ?> +| <body> + +#data +<html><body></body><?something> +#errors +#document +| <html> +| <head> +| <body> +| <?something ?> + +#data +<html><body></body></html><?something> +#errors +#document +| <html> +| <head> +| <body> +| <?something ?> + +#data +<body><template><?something></template> +#errors +#document +| <html> +| <head> +| <body> +| <template> +| content +| <?something ?> + +#data +<body><textarea><?something></textarea> +#errors +#document +| <html> +| <head> +| <body> +| <textarea> +| "<?something>" + +#data +<body><title><?something></title> +#errors +#document +| <html> +| <head> +| <body> +| <title> +| "<?something>" + +#data +<noscript><?pi> +#errors +#script-off +#document +| <html> +| <head> +| <noscript> +| <?pi ?> +| <body> + +#data +<template><?pi> +#errors +#document +| <html> +| <head> +| <template> +| content +| <?pi ?> +| <body> + diff --git a/rcdom/wpt-tree-construction-tests/scripted_foster01.dat b/rcdom/wpt-tree-construction-tests/scripted_foster01.dat new file mode 100644 index 00000000..a99760a3 --- /dev/null +++ b/rcdom/wpt-tree-construction-tests/scripted_foster01.dat @@ -0,0 +1,21 @@ +#data +<table><tr><script>var t=document.querySelector('table');document.documentElement.remove();document.appendChild(t)</script><b> +#errors +#script-on +#document +| <table> +| <tbody> +| <tr> +| <script> +| "var t=document.querySelector('table');document.documentElement.remove();document.appendChild(t)" + +#data +<table><tr><script>var t=document.querySelector('table');document.documentElement.remove();document.appendChild(t)</script>FOSTERTEXT +#errors +#script-on +#document +| <table> +| <tbody> +| <tr> +| <script> +| "var t=document.querySelector('table');document.documentElement.remove();document.appendChild(t)" diff --git a/rcdom/wpt-tree-construction-tests/search-element.dat b/rcdom/wpt-tree-construction-tests/search-element.dat index 2866d7ec..052ee598 100644 --- a/rcdom/wpt-tree-construction-tests/search-element.dat +++ b/rcdom/wpt-tree-construction-tests/search-element.dat @@ -1,3 +1,5 @@ +#description +search start tag closes an open p element #data <!doctype html><p>foo<search>bar<p>baz #errors @@ -44,3 +46,87 @@ | <svg a> | <svg search> | <b> + +#data +<!doctype html><a><search>x</a>y +#errors + * (1,32) adoption agency: formatting element is not the current node + * (1,33) unexpected end of file +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <a> +| <search> +| <a> +| "x" +| "y" + +#data +<!doctype html><a><search>x<p>y<a>z +#errors + * (1,34) unexpected start tag a implies end tag a + * (1,35) unexpected end of file +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <a> +| <search> +| <a> +| "x" +| <p> +| <a> +| "y" +| <a> +| "z" + +#description +search is in the special category, so an li start tag does not close the li outside it +#data +<!doctype html><li>a<search><li>b +#errors + * (1,35) unexpected end of file +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <li> +| "a" +| <search> +| <li> +| "b" + +#description +search is in the special category, so a dt start tag does not close the dd outside it +#data +<!doctype html><dd>a<search><dt>b +#errors + * (1,35) unexpected end of file +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <dd> +| "a" +| <search> +| <dt> +| "b" + +#data +<!doctype html><x><search></x>y +#errors + * (1,30) unexpected end tag x + * (1,31) unexpected end of file +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <x> +| <search> +| "y" diff --git a/rcdom/wpt-tree-construction-tests/template.dat b/rcdom/wpt-tree-construction-tests/template.dat index 45fb507c..11888f30 100644 --- a/rcdom/wpt-tree-construction-tests/template.dat +++ b/rcdom/wpt-tree-construction-tests/template.dat @@ -603,6 +603,86 @@ bad frameset | <span> | <span> +#data +<head><template></template></head><p><frameset> +#errors +no doctype +bad frameset +eof in frameset +#document +| <html> +| <head> +| <template> +| content +| <frameset> + +#data +<template>x</template><p><frameset> +#errors +no doctype +bad frameset +eof in frameset +#document +| <html> +| <head> +| <template> +| content +| "x" +| <frameset> + +#data +<head></head><template></template><p><frameset> +#errors +no doctype +bad template +bad frameset +eof in frameset +#document +| <html> +| <head> +| <template> +| content +| <frameset> + +#data +<p><template></template><frameset> +#errors +no doctype +bad frameset +#document +| <html> +| <head> +| <body> +| <p> +| <template> +| content + +#data +<p><template><frameset></template> +#errors +no doctype +bad frameset +#document +| <html> +| <head> +| <body> +| <p> +| <template> +| content + +#data +<template></template>x<frameset> +#errors +no doctype +bad frameset +#document +| <html> +| <head> +| <template> +| content +| <body> +| "x" + #data <body><template><script>var i = 1;</script><td></td></template> #errors @@ -632,6 +712,23 @@ foster-parented /div | <tr> | <div> +#data +<table><template><tr><div></div></tr></template> +#errors +no doctype +foster-parented div +foster-parented /div +eof in table +#document +| <html> +| <head> +| <body> +| <table> +| <template> +| content +| <tr> +| <div> + #data <body><template><tr></tr><td></td></template> #errors @@ -1624,6 +1721,115 @@ template | <div> | "second" +#data +<template><table><form></table></template> +#errors +no doctype +unexpected form in table +#document +| <html> +| <head> +| <template> +| content +| <table> +| <form> +| <body> + +#data +<table><form></table> +#errors +unexpected form in table +#document-fragment +template +#document +| <table> +| <form> + +#description +form start tags inside template do not set the form element pointer, so nested forms are kept +#data +<template><form><form><input></template> +#errors +no doctype +#document +| <html> +| <head> +| <template> +| content +| <form> +| <form> +| <input> +| <body> + +#data +<form><form> +#errors +#document-fragment +template +#document +| <form> +| <form> + +#data +<template><form><template></template><form></template> +#errors +no doctype +#document +| <html> +| <head> +| <template> +| content +| <form> +| <template> +| content +| <form> +| <body> + +#data +<template><template><form></template><form></template> +#errors +no doctype +#document +| <html> +| <head> +| <template> +| content +| <template> +| content +| <form> +| <form> +| <body> + +#data +<form><template><form></template><form> +#errors +no doctype +nested form ignored +#document +| <html> +| <head> +| <body> +| <form> +| <template> +| content +| <form> + +#data +<br>BC<form>D<div>E</form>F</div>G +#errors +unexpected end tag +unexpected end tag +#document-fragment +template +#document +| <br> +| "BC" +| <form> +| "D" +| <div> +| "E" +| "FG" + #data <!DOCTYPE HTML><template><tr><td>cell</td></tr></template> #errors diff --git a/rcdom/wpt-tree-construction-tests/test.js b/rcdom/wpt-tree-construction-tests/test.js index 0f6a9ab4..d993273e 100644 --- a/rcdom/wpt-tree-construction-tests/test.js +++ b/rcdom/wpt-tree-construction-tests/test.js @@ -55,6 +55,9 @@ case Node.COMMENT_NODE: lines.push(`|${pad}<!-- ${node.nodeValue} -->`); break; + case Node.PROCESSING_INSTRUCTION_NODE: + lines.push(`|${pad}<?${node.target} ${node.data || ""}?>`); + break; case Node.TEXT_NODE: lines.push(`|${pad}"${node.nodeValue}"`); break; @@ -141,6 +144,7 @@ }; // .dat format (html5lib-tests): + // #description appended to the test name // #data input HTML // #errors / #new-errors / #errors-new parsing errors (ignored here) // #script-on / #script-off scripting requirement (we honor #script-off) @@ -174,7 +178,7 @@ const line = fileLines[i] + (i === fileLines.length - 1 ? "" : "\n"); const heading = isSectionHeading(line); if (heading) { - if (data && heading === "data") { + if (data && (heading === "description" || (heading === "data" && key !== "description"))) { if (key !== null && data[key].length > 0) { data[key] = data[key].slice(0, -1); } @@ -191,6 +195,7 @@ if (data) cases.push(normalise(data)); return cases.map(c => ({ + description: c["description"], data: c["data"] ?? "", document: c["document"] ?? "", fragment: c["document-fragment"], @@ -256,9 +261,12 @@ // go through innerHTML), so we run them in only one wrapper to avoid // counting the same assertion three times. if (c.fragment !== undefined && runType !== "url") continue; - const name = c.fragment !== undefined + const base = c.fragment !== undefined ? `${escapeForName(c.data)} (innerHTML in ${c.fragment})` : escapeForName(c.data); + const name = c.description + ? `${base}: ${escapeForName(c.description)}` + : base; // Identical (input, fragment-context) pairs would collide as test // names. Upstream html5lib-tests doesn't ship any (after #script-off // is filtered out); if that ever changes we want to know rather than diff --git a/rcdom/wpt-tree-construction-tests/tests1.dat b/rcdom/wpt-tree-construction-tests/tests1.dat index 15d496eb..c4837b47 100644 --- a/rcdom/wpt-tree-construction-tests/tests1.dat +++ b/rcdom/wpt-tree-construction-tests/tests1.dat @@ -551,12 +551,10 @@ Line1<br>Line2<br>Line3<br>Line4 #data <? #errors -(1,1): expected-tag-name-but-got-question-mark (1,2): expected-doctype-but-got-eof #new-errors -(1:2) unexpected-question-mark-instead-of-tag-name +(1:3) eof-in-processing-instruction #document -| <!-- ? --> | <html> | <head> | <body> @@ -564,10 +562,9 @@ Line1<br>Line2<br>Line3<br>Line4 #data <?# #errors -(1,1): expected-tag-name-but-got-question-mark (1,3): expected-doctype-but-got-eof #new-errors -(1:2) unexpected-question-mark-instead-of-tag-name +(1:3) invalid-first-character-of-processing-instruction-target #document | <!-- ?# --> | <html> @@ -603,12 +600,9 @@ Line1<br>Line2<br>Line3<br>Line4 #data <?COMMENT?> #errors -(1,1): expected-tag-name-but-got-question-mark (1,11): expected-doctype-but-got-eof -#new-errors -(1:2) unexpected-question-mark-instead-of-tag-name #document -| <!-- ?COMMENT? --> +| <?COMMENT ?> | <html> | <head> | <body> @@ -642,12 +636,9 @@ Line1<br>Line2<br>Line3<br>Line4 #data <?COM--MENT?> #errors -(1,1): expected-tag-name-but-got-question-mark (1,13): expected-doctype-but-got-eof -#new-errors -(1:2) unexpected-question-mark-instead-of-tag-name #document -| <!-- ?COM--MENT? --> +| <?COM--MENT ?> | <html> | <head> | <body> diff --git a/rcdom/wpt-tree-construction-tests/tests19.dat b/rcdom/wpt-tree-construction-tests/tests19.dat index 20cdeabc..8b133d39 100644 --- a/rcdom/wpt-tree-construction-tests/tests19.dat +++ b/rcdom/wpt-tree-construction-tests/tests19.dat @@ -605,6 +605,64 @@ | <p> | "a" +#description +U+FFFD character sets frameset-ok to "not ok" +#data +<!doctype html>�<frameset><frame> +#errors +(1,26): unexpected-start-tag +(1,33): unexpected-start-tag-ignored +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| "�" + +#description +U+FFFD from a character reference sets frameset-ok to "not ok" +#data +<!doctype html>&#xFFFD;<frameset><frame> +#errors +(1,33): unexpected-start-tag +(1,40): unexpected-start-tag-ignored +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| "�" + +#description +Null character reference becomes U+FFFD and sets frameset-ok to "not ok" +#data +<!doctype html>&#0;<frameset><frame> +#errors +(1,19): null-character-reference +(1,29): unexpected-start-tag +(1,36): unexpected-start-tag-ignored +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| "�" + +#description +U+FFFD in foreign content sets frameset-ok to "not ok" +#data +<!doctype html><svg>&#xFFFD;</svg><frameset><frame> +#errors +(1,44): unexpected-start-tag +(1,51): unexpected-start-tag-ignored +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <svg svg> +| "�" + #data <!doctype html><p> <frameset><frame> #errors diff --git a/rcdom/wpt-tree-construction-tests/tests4.dat b/rcdom/wpt-tree-construction-tests/tests4.dat index 4f0cf70e..53770de9 100644 --- a/rcdom/wpt-tree-construction-tests/tests4.dat +++ b/rcdom/wpt-tree-construction-tests/tests4.dat @@ -14,6 +14,8 @@ textarea #document | "direct textarea content" +#description +textarea context puts the tokenizer in RCDATA, so tags are text #data textarea content with <em>pseudo</em> <foo>markup #errors @@ -22,6 +24,8 @@ textarea #document | "textarea content with <em>pseudo</em> <foo>markup" +#description +style context puts the tokenizer in RAWTEXT, so character references are not decoded #data this is &#x0043;DATA inside a <style> element #errors @@ -30,6 +34,8 @@ style #document | "this is &#x0043;DATA inside a <style> element" +#description +plaintext context puts the tokenizer in PLAINTEXT, so even its end tag is text #data </plaintext> #errors diff --git a/rcdom/wpt-tree-construction-tests/tests_innerHTML_1.dat b/rcdom/wpt-tree-construction-tests/tests_innerHTML_1.dat index 78416d48..09e0456f 100644 --- a/rcdom/wpt-tree-construction-tests/tests_innerHTML_1.dat +++ b/rcdom/wpt-tree-construction-tests/tests_innerHTML_1.dat @@ -790,10 +790,10 @@ select #data <input><option> #errors +(1,7): XXX-undefined-error #document-fragment select #document -| <input> | <option> #data diff --git a/rcdom/wpt-tree-construction-tests/void-in-phrasing.dat b/rcdom/wpt-tree-construction-tests/void-in-phrasing.dat new file mode 100644 index 00000000..b7dbd1e7 --- /dev/null +++ b/rcdom/wpt-tree-construction-tests/void-in-phrasing.dat @@ -0,0 +1,151 @@ +#data +<!DOCTYPE html><body><p><br></p> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <p> +| <br> + +#data +<!DOCTYPE html><body><p><br>text</p> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <p> +| <br> +| "text" + +#data +<!DOCTYPE html><body><p>before<br>after</p> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <p> +| "before" +| <br> +| "after" + +#data +<!DOCTYPE html><body><p><br><br></p> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <p> +| <br> +| <br> + +#data +<!DOCTYPE html><body><p>a<br>b<br>c</p> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <p> +| "a" +| <br> +| "b" +| <br> +| "c" + +#data +<!DOCTYPE html><body><h1><br></h1> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <h1> +| <br> + +#data +<!DOCTYPE html><body><p><input></p> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <p> +| <input> + +#data +<!DOCTYPE html><body><p><img></p> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <p> +| <img> + +#data +<!DOCTYPE html><body><p><wbr></p> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <p> +| <wbr> + +#data +<!DOCTYPE html><body><p><embed></p> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <p> +| <embed> + +#data +<!DOCTYPE html><body><h2><input></h2> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <h2> +| <input> + +#data +<!DOCTYPE html><body><em><br></em> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <em> +| <br> + +#data +<!DOCTYPE html><body><strong><br>text</strong> +#errors +#document +| <!DOCTYPE html> +| <html> +| <head> +| <body> +| <strong> +| <br> +| "text" diff --git a/rcdom/wpt-tree-construction-tests/webkit02.dat b/rcdom/wpt-tree-construction-tests/webkit02.dat index 9007f2fd..47a3c571 100644 --- a/rcdom/wpt-tree-construction-tests/webkit02.dat +++ b/rcdom/wpt-tree-construction-tests/webkit02.dat @@ -728,3 +728,48 @@ eof-in-math | "ib" | <b> | "b" + +#data +<select><button><selectedcontent></button><option>X<option>Y +#errors +#document +| <html> +| <head> +| <body> +| <select> +| <button> +| <selectedcontent> +| "X" +| <option> +| "X" +| <option> +| "Y" + +#data +<select><button><selectedcontent></button><option>X<option selected>Y +#errors +#document +| <html> +| <head> +| <body> +| <select> +| <button> +| <selectedcontent> +| "Y" +| <option> +| "X" +| <option> +| selected="" +| "Y" + +#data +<font><select><option>a</option></font></select> +#errors +#document +| <html> +| <head> +| <body> +| <font> +| <select> +| <option> +| "a"