From 5f288d473cb5f5aa534a89a16fbed8a8950ad172 Mon Sep 17 00:00:00 2001 From: darkuss Date: Tue, 29 Sep 2026 04:10:04 +0200 Subject: [PATCH 01/23] feat: add support for processing instructions --- html5ever/src/tokenizer/interface.rs | 11 +- html5ever/src/tokenizer/mod.rs | 158 ++++++++++++++++++++++++++- html5ever/src/tokenizer/states.rs | 10 ++ html5ever/src/tree_builder/mod.rs | 7 ++ html5ever/src/tree_builder/rules.rs | 4 + html5ever/src/tree_builder/types.rs | 1 + rcdom/tests/html-serializer.rs | 1 + rcdom/tests/html-tokenizer.rs | 10 +- 8 files changed, 193 insertions(+), 9 deletions(-) diff --git a/html5ever/src/tokenizer/interface.rs b/html5ever/src/tokenizer/interface.rs index b1436a71..faabf720 100644 --- a/html5ever/src/tokenizer/interface.rs +++ b/html5ever/src/tokenizer/interface.rs @@ -16,7 +16,7 @@ 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, TagToken, ProcessingInstructionToken}; pub use self::Token::{EOFToken, NullCharacterToken, ParseError}; /// A `DOCTYPE` token. @@ -79,6 +79,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 +94,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..5220f4cd 100644 --- a/html5ever/src/tokenizer/mod.rs +++ b/html5ever/src/tokenizer/mod.rs @@ -10,8 +10,8 @@ //! 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, TagToken, ProcessingInstructionToken, Token}; +pub use self::interface::{Doctype, EndTag, StartTag, Tag, TagKind, ProcessingInstruction}; pub use self::interface::{TokenSink, TokenSinkResult}; use self::states::AttrValueKind::*; @@ -167,6 +167,9 @@ pub struct Tokenizer { /// Current doctype token. current_doctype: RefCell, + /// Current processing instruction token + current_pi: RefCell, + /// Last start tag name, for use in checking "appropriate end tag". last_start_tag_name: RefCell>, @@ -211,6 +214,7 @@ impl Tokenizer { current_attr_value: RefCell::new(StrTendril::new()), current_comment: RefCell::new(StrTendril::new()), current_doctype: RefCell::new(Doctype::default()), + current_pi: 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 +629,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 + let buf = mem::take(&mut *self.temp_buf.borrow_mut()); + comment.push_tendril(&buf); + } + + fn emit_current_pi(&self) { + let pi = self.current_pi.take(); + self.process_token_and_continue(ProcessingInstructionToken(pi)); + } } //§ END @@ -650,6 +669,10 @@ macro_rules! shorthand ( ( $me:ident : clear_doctype_id $k:ident ) => ( $me.clear_doctype_id($k) ); ( $me:ident : force_quirks ) => ( $me.current_doctype.borrow_mut().force_quirks = true); ( $me:ident : emit_doctype ) => ( $me.emit_current_doctype() ); + ( $me:ident : convert_to_comment ) => ( $me.convert_to_comment() ); + ( $me:ident : create_pi $target:expr ) => ( *$me.current_pi.borrow_mut() = ProcessingInstruction { target: $target, data: Default::default() } ); + ( $me:ident : push_pi_data $c:expr ) => ( $me.current_pi.borrow_mut().data.push_char($c) ); + ( $me:ident : emit_pi ) => ( $me.emit_current_pi() ); ); // Tracing of tokenizer actions. This adds significant bloat and compile time, @@ -940,8 +963,9 @@ 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) + // self.bad_char_error(); + // go!(self: clear_comment; reconsume BogusComment) + go!(self: clear_temp; to State::ProcessingInstructionOpen); }, // ↪ Anything else _ => { @@ -2654,7 +2678,123 @@ 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(); + go!(self: convert_to_comment; 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 target = self.temp_buf.take(); + // If target is an ASCII case-insensitive match for "xml" or "xml-stylesheet": + if target.to_lowercase() == "xml" || target.to_lowercase() == "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.bad_char_error(); + go!(self: convert_to_comment; reconsume BogusComment); + } else { + // Create a processing instruction token whose target is target and data is the empty string. + // Reconsume in the after processing instruction target state. + go!(self: create_pi target; reconsume AfterProcessingInstructionTarget); + } + }, + // ↪ ASCII alphanumeric + // ↪ U+002D HYPHEN-MINUS (-) + // ↪ U+005F LOW LINE (_) + character if character.is_ascii_alphabetic() || character == '-' || character == '_' => { + go!(self: push_temp character); + } + // ↪ 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(); + go!(self: convert_to_comment; 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. + go!(self: emit_pi; to State::Data) + } + // ↪ Anything else + character => { + // Append the current input character to the current processing instruction token's data. + go!(self: push_pi_data 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. + go!(self: emit_pi; to State::Data) + } + // ↪ Anything else + _ => { + // Append U+003F (?) to the current processing instruction token's data. Reconsume in the processing instruction data state. + go!(self: push_pi_data '?'; reconsume ProcessingInstructionData); + } + } + } + //§ END } } @@ -2775,7 +2915,13 @@ 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..84a921aa 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..5f26413c 100644 --- a/html5ever/src/tree_builder/mod.rs +++ b/html5ever/src/tree_builder/mod.rs @@ -526,6 +526,7 @@ 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 +1343,12 @@ where ProcessResult::Done } + fn append_pi(&self, target: StrTendril, data: StrTendril) -> ProcessResult { + let pi = self.sink.create_pi(target, data); + self.insert_appropriately(AppendNode(pi), None); + 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..c44f576e 100644 --- a/html5ever/src/tree_builder/rules.rs +++ b/html5ever/src/tree_builder/rules.rs @@ -424,6 +424,8 @@ where Token::Comment(text) => self.append_comment(text), + Token::ProcessingInstruction(target, data) => self.append_pi(target, data), + Token::Tag(tag @ tag!()) => { self.unexpected(&tag); if !self.in_html_elem_named(local_name!("template")) { @@ -1632,6 +1634,8 @@ where Token::Comment(text) => self.append_comment(text), + Token::ProcessingInstruction(target, data) => self.append_pi(target, data), + Token::Tag( tag @ tag!( | |
| |
|
| |
|
|
| 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/tests/html-serializer.rs b/rcdom/tests/html-serializer.rs index 176a417d..713247f1 100644 --- a/rcdom/tests/html-serializer.rs +++ b/rcdom/tests/html-serializer.rs @@ -57,6 +57,7 @@ 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:#?}"), diff --git a/rcdom/tests/html-tokenizer.rs b/rcdom/tests/html-tokenizer.rs index 7ac8767a..dc1e6be5 100644 --- a/rcdom/tests/html-tokenizer.rs +++ b/rcdom/tests/html-tokenizer.rs @@ -16,8 +16,8 @@ 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, TagToken, ProcessingInstructionToken, Token}; +use html5ever::tokenizer::{Doctype, EndTag, StartTag, Tag, ProcessingInstruction}; use html5ever::tokenizer::{TokenSink, TokenSinkResult, Tokenizer, TokenizerOpts}; use html5ever::TokenizerResult; use html5ever::{ns, Attribute, LocalName, QualName}; @@ -264,8 +264,14 @@ 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 // the TokenLogger will convert them to CharacterTokens. _ => panic!("don't understand token {parts:?}"), From c054ea4bef09a859e5c590a25da86de8f44004ca Mon Sep 17 00:00:00 2001 From: darkuss Date: Tue, 29 Sep 2026 04:17:13 +0200 Subject: [PATCH 02/23] chore: run `cargo fmt` --- rcdom/tests/html-serializer.rs | 4 +++- rcdom/tests/html-tokenizer.rs | 9 +++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/rcdom/tests/html-serializer.rs b/rcdom/tests/html-serializer.rs index 713247f1..54018619 100644 --- a/rcdom/tests/html-serializer.rs +++ b/rcdom/tests/html-serializer.rs @@ -57,7 +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::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:#?}"), diff --git a/rcdom/tests/html-tokenizer.rs b/rcdom/tests/html-tokenizer.rs index dc1e6be5..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, ProcessingInstructionToken, Token}; -use html5ever::tokenizer::{Doctype, EndTag, StartTag, Tag, ProcessingInstruction}; +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}; @@ -266,12 +268,11 @@ fn json_to_token(js: &Value) -> Token { "ProcessingInstruction" => ProcessingInstructionToken(ProcessingInstruction { target: args[0].get_tendril(), - data: args[1].get_tendril() + data: args[1].get_tendril(), }), "Character" => CharacterTokens(args[0].get_tendril()), - // We don't need to produce NullCharacterToken because // the TokenLogger will convert them to CharacterTokens. _ => panic!("don't understand token {parts:?}"), From f92b5f3f466c09a76def23b62fb108d4282c2e3a Mon Sep 17 00:00:00 2001 From: darkuss Date: Wed, 30 Sep 2026 00:33:47 +0200 Subject: [PATCH 03/23] chore: cleanup commented out code --- html5ever/src/tokenizer/mod.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/html5ever/src/tokenizer/mod.rs b/html5ever/src/tokenizer/mod.rs index 5220f4cd..d0f81157 100644 --- a/html5ever/src/tokenizer/mod.rs +++ b/html5ever/src/tokenizer/mod.rs @@ -963,8 +963,6 @@ 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 From dac1bb8fb15a09cedb67f08bd832a48778504b5f Mon Sep 17 00:00:00 2001 From: darkuss Date: Sat, 3 Oct 2026 11:25:26 +0200 Subject: [PATCH 04/23] chore: fix links in the states enum --- html5ever/src/tokenizer/states.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/html5ever/src/tokenizer/states.rs b/html5ever/src/tokenizer/states.rs index 84a921aa..89a2d80d 100644 --- a/html5ever/src/tokenizer/states.rs +++ b/html5ever/src/tokenizer/states.rs @@ -130,12 +130,12 @@ pub enum State { CdataSectionEnd, /// ProcessingInstructionOpen, - /// + /// ProcessingInstructionTarget, - /// + /// AfterProcessingInstructionTarget, - /// + /// ProcessingInstructionData, - /// + /// ProcessingInstructionQuestionable, } From f01208871b107e9dc6a1c48711ca93369ae460d2 Mon Sep 17 00:00:00 2001 From: darkuss Date: Sat, 3 Oct 2026 11:31:03 +0200 Subject: [PATCH 05/23] fix: only take the temporary buffer when needed in `states::ProcessingInstructionTarget` --- html5ever/src/tokenizer/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/html5ever/src/tokenizer/mod.rs b/html5ever/src/tokenizer/mod.rs index d0f81157..553b212f 100644 --- a/html5ever/src/tokenizer/mod.rs +++ b/html5ever/src/tokenizer/mod.rs @@ -2707,7 +2707,7 @@ impl Tokenizer { // ↪ 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 target = self.temp_buf.take(); + let target = self.temp_buf.borrow(); // If target is an ASCII case-insensitive match for "xml" or "xml-stylesheet": if target.to_lowercase() == "xml" || target.to_lowercase() == "xml-stylesheet" { // This is a disallowed-processing-instruction-target parse error. @@ -2716,6 +2716,8 @@ impl Tokenizer { self.bad_char_error(); go!(self: convert_to_comment; reconsume BogusComment); } else { + drop(target); + 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. go!(self: create_pi target; reconsume AfterProcessingInstructionTarget); From 1e09d22c840292d89b36466cbdbab5274f517fb1 Mon Sep 17 00:00:00 2001 From: darkuss Date: Sat, 3 Oct 2026 11:33:10 +0200 Subject: [PATCH 06/23] fix: also process numbers in `states::ProcessingInstructionTarget` --- html5ever/src/tokenizer/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html5ever/src/tokenizer/mod.rs b/html5ever/src/tokenizer/mod.rs index 553b212f..d4dd1765 100644 --- a/html5ever/src/tokenizer/mod.rs +++ b/html5ever/src/tokenizer/mod.rs @@ -2726,7 +2726,7 @@ impl Tokenizer { // ↪ ASCII alphanumeric // ↪ U+002D HYPHEN-MINUS (-) // ↪ U+005F LOW LINE (_) - character if character.is_ascii_alphabetic() || character == '-' || character == '_' => { + character if character.is_ascii_alphanumeric() || character == '-' || character == '_' => { go!(self: push_temp character); } // ↪ Anything else From 43ba53238cc56d72b5c9f8f7f6a54dc06e81cadb Mon Sep 17 00:00:00 2001 From: darkuss Date: Sat, 3 Oct 2026 11:34:54 +0200 Subject: [PATCH 07/23] chore: add missing spec text --- html5ever/src/tokenizer/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/html5ever/src/tokenizer/mod.rs b/html5ever/src/tokenizer/mod.rs index d4dd1765..b5f46bd9 100644 --- a/html5ever/src/tokenizer/mod.rs +++ b/html5ever/src/tokenizer/mod.rs @@ -2727,7 +2727,8 @@ impl Tokenizer { // ↪ U+002D HYPHEN-MINUS (-) // ↪ U+005F LOW LINE (_) character if character.is_ascii_alphanumeric() || character == '-' || character == '_' => { - go!(self: push_temp character); + // Append the current input character to the temporary buffer. + go!(self: push_temp character); } // ↪ Anything else _ => { From 81a2cbfda79a4c1ae9baf717300ffdc297ab5299 Mon Sep 17 00:00:00 2001 From: darkuss Date: Sat, 3 Oct 2026 11:50:46 +0200 Subject: [PATCH 08/23] fix: make processing instructions serialize as in the spec --- html5ever/src/serialize/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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"?>") } } From 8a6267f5c4ab1fd458d786a5c001b7783d59d37f Mon Sep 17 00:00:00 2001 From: darkuss Date: Sat, 3 Oct 2026 11:51:11 +0200 Subject: [PATCH 09/23] test: add tests for processing instruction serialization --- rcdom/tests/html-serializer.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/rcdom/tests/html-serializer.rs b/rcdom/tests/html-serializer.rs index 54018619..0e39699e 100644 --- a/rcdom/tests/html-serializer.rs +++ b/rcdom/tests/html-serializer.rs @@ -246,8 +246,39 @@ test!(attr_ns_2, r#""#); test!(attr_ns_3, r#""#); test!(attr_ns_4, r#""#); +test!( + processing_instruction_1, + r#""#, + r#""# +); + +test!( + processing_instruction_2, + r#""#, + r#""# +); + +test!( + processing_instruction_3, + r#""#, + r#""# +); + +test!( + processing_instruction_4, + r#""#, + r#""# +); + +test!( + processing_instruction_5, + r#""#, + r#""# +); + test_no_parse!(malformed_tokens, r#"foo
"#); + #[test] fn doctype() { let dom = parse_document(RcDom::default(), ParseOpts::default()).one(""); From 41b34dcc4ecdf349a240e8c3eef4a3b98dcdb591 Mon Sep 17 00:00:00 2001 From: darkuss Date: Sat, 3 Oct 2026 12:04:35 +0200 Subject: [PATCH 10/23] chore: make things using `pi` use `processing_instruction` instead --- html5ever/src/tokenizer/mod.rs | 35 ++++++++++++++++------------- html5ever/src/tree_builder/mod.rs | 2 +- html5ever/src/tree_builder/rules.rs | 4 ++-- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/html5ever/src/tokenizer/mod.rs b/html5ever/src/tokenizer/mod.rs index b5f46bd9..863d6735 100644 --- a/html5ever/src/tokenizer/mod.rs +++ b/html5ever/src/tokenizer/mod.rs @@ -168,7 +168,7 @@ pub struct Tokenizer { current_doctype: RefCell, /// Current processing instruction token - current_pi: RefCell, + current_processing_instruction: RefCell, /// Last start tag name, for use in checking "appropriate end tag". last_start_tag_name: RefCell>, @@ -214,7 +214,7 @@ impl Tokenizer { current_attr_value: RefCell::new(StrTendril::new()), current_comment: RefCell::new(StrTendril::new()), current_doctype: RefCell::new(Doctype::default()), - current_pi: RefCell::new(ProcessingInstruction::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()), @@ -640,8 +640,8 @@ impl Tokenizer { comment.push_tendril(&buf); } - fn emit_current_pi(&self) { - let pi = self.current_pi.take(); + fn emit_current_processing_instruction(&self) { + let pi = self.current_processing_instruction.take(); self.process_token_and_continue(ProcessingInstructionToken(pi)); } } @@ -669,10 +669,6 @@ macro_rules! shorthand ( ( $me:ident : clear_doctype_id $k:ident ) => ( $me.clear_doctype_id($k) ); ( $me:ident : force_quirks ) => ( $me.current_doctype.borrow_mut().force_quirks = true); ( $me:ident : emit_doctype ) => ( $me.emit_current_doctype() ); - ( $me:ident : convert_to_comment ) => ( $me.convert_to_comment() ); - ( $me:ident : create_pi $target:expr ) => ( *$me.current_pi.borrow_mut() = ProcessingInstruction { target: $target, data: Default::default() } ); - ( $me:ident : push_pi_data $c:expr ) => ( $me.current_pi.borrow_mut().data.push_char($c) ); - ( $me:ident : emit_pi ) => ( $me.emit_current_pi() ); ); // Tracing of tokenizer actions. This adds significant bloat and compile time, @@ -2691,7 +2687,8 @@ impl Tokenizer { // 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(); - go!(self: convert_to_comment; reconsume BogusComment); + self.convert_to_comment(); + go!(self: reconsume BogusComment); } } } @@ -2714,13 +2711,15 @@ impl Tokenizer { // Convert the temporary buffer to a comment. // Reconsume in the bogus comment state. self.bad_char_error(); - go!(self: convert_to_comment; reconsume BogusComment); + self.convert_to_comment(); + go!(self: reconsume BogusComment); } else { drop(target); 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. - go!(self: create_pi target; reconsume AfterProcessingInstructionTarget); + *self.current_processing_instruction.borrow_mut() = ProcessingInstruction { target, data: Default::default() }; + go!(self: reconsume AfterProcessingInstructionTarget); } }, // ↪ ASCII alphanumeric @@ -2735,7 +2734,8 @@ impl Tokenizer { // 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(); - go!(self: convert_to_comment; reconsume BogusComment); + self.convert_to_comment(); + go!(self: reconsume BogusComment); } } } @@ -2770,12 +2770,13 @@ impl Tokenizer { // ↪ U+003E GREATER-THAN SIGN (>) '>' => { // Switch to the data state. Emit the current processing instruction token. - go!(self: emit_pi; to State::Data) + 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. - go!(self: push_pi_data character); + self.current_processing_instruction.borrow_mut().data.push_char(character); } } } @@ -2786,12 +2787,14 @@ impl Tokenizer { // ↪ U+003E GREATER-THAN SIGN (>) '>' => { // Switch to the data state. Emit the current processing instruction token. - go!(self: emit_pi; to State::Data) + 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. - go!(self: push_pi_data '?'; reconsume ProcessingInstructionData); + self.current_processing_instruction.borrow_mut().data.push_char('?'); + go!(self: reconsume ProcessingInstructionData); } } } diff --git a/html5ever/src/tree_builder/mod.rs b/html5ever/src/tree_builder/mod.rs index 5f26413c..bf78c504 100644 --- a/html5ever/src/tree_builder/mod.rs +++ b/html5ever/src/tree_builder/mod.rs @@ -1343,7 +1343,7 @@ where ProcessResult::Done } - fn append_pi(&self, target: StrTendril, data: StrTendril) -> ProcessResult { + fn append_processing_instruction(&self, target: StrTendril, data: StrTendril) -> ProcessResult { let pi = self.sink.create_pi(target, data); self.insert_appropriately(AppendNode(pi), None); ProcessResult::Done diff --git a/html5ever/src/tree_builder/rules.rs b/html5ever/src/tree_builder/rules.rs index c44f576e..576c68c8 100644 --- a/html5ever/src/tree_builder/rules.rs +++ b/html5ever/src/tree_builder/rules.rs @@ -424,7 +424,7 @@ where Token::Comment(text) => self.append_comment(text), - Token::ProcessingInstruction(target, data) => self.append_pi(target, data), + Token::ProcessingInstruction(target, data) => self.append_processing_instruction(target, data), Token::Tag(tag @ tag!()) => { self.unexpected(&tag); @@ -1634,7 +1634,7 @@ where Token::Comment(text) => self.append_comment(text), - Token::ProcessingInstruction(target, data) => self.append_pi(target, data), + Token::ProcessingInstruction(target, data) => self.append_processing_instruction(target, data), Token::Tag( tag @ From 6afc2a1093722241649f3f63a70672ce29391d64 Mon Sep 17 00:00:00 2001 From: darkuss Date: Sat, 3 Oct 2026 12:23:25 +0200 Subject: [PATCH 11/23] fix: parse processing instructions in all of the needed insertion modes --- html5ever/src/tree_builder/mod.rs | 14 ++++++++++++++ html5ever/src/tree_builder/rules.rs | 16 ++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/html5ever/src/tree_builder/mod.rs b/html5ever/src/tree_builder/mod.rs index bf78c504..749b4543 100644 --- a/html5ever/src/tree_builder/mod.rs +++ b/html5ever/src/tree_builder/mod.rs @@ -1349,6 +1349,20 @@ where ProcessResult::Done } + fn append_processing_instruction_to_doc(&self, target: StrTendril, data: StrTendril) -> ProcessResult { + let pi = self.sink.create_pi(target, data); + self.sink.append(&self.doc_handle, AppendNode(pi)); + ProcessResult::Done + } + + fn append_processing_instruction_to_html(&self, target: StrTendril, data: StrTendril) -> ProcessResult { + let open_elems = self.open_elems.borrow(); + let el_target = html_elem(&open_elems); + let pi = self.sink.create_pi(target, data); + self.sink.append(el_target, AppendNode(pi)); + 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 576c68c8..ba75abee 100644 --- a/html5ever/src/tree_builder/rules.rs +++ b/html5ever/src/tree_builder/rules.rs @@ -104,6 +104,7 @@ 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 +125,8 @@ 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 +158,7 @@ where }, Token::Characters(SplitStatus::Whitespace, _) => ProcessResult::Done, Token::Comment(text) => self.append_comment(text), + Token::ProcessingInstruction(target, data) => self.append_processing_instruction_to_doc(target, data), Token::Tag(tag!()) => self.step(InsertionMode::InBody, token), @@ -186,6 +190,7 @@ 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_to_doc(target, data), Token::Tag(tag!()) => self.step(InsertionMode::InBody, token), @@ -338,6 +343,7 @@ where }, Token::Comment(_) => self.step(InsertionMode::InHead, token), + Token::ProcessingInstruction(target, data) => self.append_processing_instruction_to_doc(target, data), Token::Tag( tag!( | | | | | <style>), @@ -365,6 +371,7 @@ 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_to_doc(target, data), Token::Tag(tag!(<html>)) => self.step(InsertionMode::InBody, token), @@ -1040,6 +1047,8 @@ where Token::NullCharacter | Token::Characters(..) => self.process_chars_in_table(token), 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); @@ -1214,6 +1223,7 @@ 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_to_doc(target, data), Token::Tag(tag!(<html>)) => self.step(InsertionMode::InBody, token), @@ -1416,6 +1426,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> | @@ -1484,6 +1495,7 @@ 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), @@ -1512,6 +1524,7 @@ 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), @@ -1558,6 +1571,7 @@ 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), @@ -1583,6 +1597,7 @@ 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), @@ -1604,6 +1619,7 @@ 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), From 55863b126a160467223dd18ee90799381b33d29c Mon Sep 17 00:00:00 2001 From: darkuss <darkussdelta@gmail.com> Date: Sat, 3 Oct 2026 12:27:08 +0200 Subject: [PATCH 12/23] ref: emit custom error instead of using `bad_char` for `disallowed-processing-instruction-target` --- html5ever/src/tokenizer/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html5ever/src/tokenizer/mod.rs b/html5ever/src/tokenizer/mod.rs index 863d6735..050a66af 100644 --- a/html5ever/src/tokenizer/mod.rs +++ b/html5ever/src/tokenizer/mod.rs @@ -2710,7 +2710,7 @@ impl<Sink: TokenSink> Tokenizer<Sink> { // This is a disallowed-processing-instruction-target parse error. // Convert the temporary buffer to a comment. // Reconsume in the bogus comment state. - self.bad_char_error(); + self.emit_error(Borrowed("Disallowed processing instruction target")); self.convert_to_comment(); go!(self: reconsume BogusComment); } else { From 779f0ec1019dc761f9f3aeb85c12f2cd749acbe9 Mon Sep 17 00:00:00 2001 From: darkuss <darkussdelta@gmail.com> Date: Sat, 3 Oct 2026 12:27:58 +0200 Subject: [PATCH 13/23] chore: run `cargo fmt` --- html5ever/src/tokenizer/interface.rs | 6 ++- html5ever/src/tokenizer/mod.rs | 70 +++++++++++++++++----------- html5ever/src/tree_builder/mod.rs | 22 +++++++-- html5ever/src/tree_builder/rules.rs | 62 +++++++++++++++++------- rcdom/tests/html-serializer.rs | 19 ++------ 5 files changed, 113 insertions(+), 66 deletions(-) diff --git a/html5ever/src/tokenizer/interface.rs b/html5ever/src/tokenizer/interface.rs index faabf720..f1029000 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, ProcessingInstructionToken}; +pub use self::Token::{ + CharacterTokens, CommentToken, DoctypeToken, ProcessingInstructionToken, TagToken, +}; pub use self::Token::{EOFToken, NullCharacterToken, ParseError}; /// A `DOCTYPE` token. @@ -83,7 +85,7 @@ impl Tag { #[derive(PartialEq, Eq, Clone, Debug, Default)] pub struct ProcessingInstruction { pub target: StrTendril, - pub data: StrTendril + pub data: StrTendril, } #[derive(PartialEq, Eq, Debug)] diff --git a/html5ever/src/tokenizer/mod.rs b/html5ever/src/tokenizer/mod.rs index 050a66af..aa0b10eb 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, ProcessingInstructionToken, Token}; -pub use self::interface::{Doctype, EndTag, StartTag, Tag, TagKind, ProcessingInstruction}; +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::*; @@ -2679,7 +2681,7 @@ impl<Sink: TokenSink> Tokenizer<Sink> { // ↪ ASCII alpha // ↪ u+005F LOW LINE (_) character if character.is_ascii_alphabetic() || character == '_' => { - // Reconsume in the processing instruction target state. + // Reconsume in the processing instruction target state. go!(self: reconsume State::ProcessingInstructionTarget); }, // ↪ Anything else @@ -2689,9 +2691,9 @@ impl<Sink: TokenSink> Tokenizer<Sink> { self.bad_char_error(); self.convert_to_comment(); go!(self: reconsume BogusComment); - } + }, } - } + }, // https://html.spec.whatwg.org/#processing-instruction-target-state states::ProcessingInstructionTarget => loop { @@ -2706,7 +2708,9 @@ impl<Sink: TokenSink> Tokenizer<Sink> { // Let target be the concatenation of the code points in the temporary buffer, in the order they were added to the buffer. let target = self.temp_buf.borrow(); // If target is an ASCII case-insensitive match for "xml" or "xml-stylesheet": - if target.to_lowercase() == "xml" || target.to_lowercase() == "xml-stylesheet" { + if target.to_lowercase() == "xml" + || target.to_lowercase() == "xml-stylesheet" + { // This is a disallowed-processing-instruction-target parse error. // Convert the temporary buffer to a comment. // Reconsume in the bogus comment state. @@ -2718,17 +2722,25 @@ impl<Sink: TokenSink> Tokenizer<Sink> { 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() }; + *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 == '_' => { + 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-first-character-of-processing-instruction-target parse error. @@ -2736,9 +2748,9 @@ impl<Sink: TokenSink> Tokenizer<Sink> { 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 { @@ -2749,15 +2761,14 @@ impl<Sink: TokenSink> Tokenizer<Sink> { // ↪ 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 { @@ -2766,20 +2777,23 @@ impl<Sink: TokenSink> Tokenizer<Sink> { '?' => { // 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); - } + self.current_processing_instruction + .borrow_mut() + .data + .push_char(character); + }, } - } + }, // https://html.spec.whatwg.org/#processing-instruction-questionable-state states::ProcessingInstructionQuestionable => loop { @@ -2789,17 +2803,18 @@ impl<Sink: TokenSink> Tokenizer<Sink> { // 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('?'); + self.current_processing_instruction + .borrow_mut() + .data + .push_char('?'); go!(self: reconsume ProcessingInstructionData); - } + }, } - } - - //§ END + }, //§ END } } @@ -2924,8 +2939,7 @@ impl<Sink: TokenSink> Tokenizer<Sink> { | states::ProcessingInstructionTarget | states::AfterProcessingInstructionTarget | states::ProcessingInstructionData - | states::ProcessingInstructionQuestionable - => { + | states::ProcessingInstructionQuestionable => { self.bad_eof_error(); go!(self: to State::Data) }, diff --git a/html5ever/src/tree_builder/mod.rs b/html5ever/src/tree_builder/mod.rs index 749b4543..4f26f387 100644 --- a/html5ever/src/tree_builder/mod.rs +++ b/html5ever/src/tree_builder/mod.rs @@ -526,7 +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::ProcessingInstructionToken(x) => { + Token::ProcessingInstruction(x.target, x.data) + }, tokenizer::NullCharacterToken => Token::NullCharacter, tokenizer::EOFToken => Token::Eof, @@ -1343,19 +1345,31 @@ where ProcessResult::Done } - fn append_processing_instruction(&self, target: StrTendril, data: StrTendril) -> ProcessResult<Handle> { + fn append_processing_instruction( + &self, + target: StrTendril, + data: StrTendril, + ) -> ProcessResult<Handle> { let pi = self.sink.create_pi(target, data); self.insert_appropriately(AppendNode(pi), None); ProcessResult::Done } - fn append_processing_instruction_to_doc(&self, target: StrTendril, data: StrTendril) -> ProcessResult<Handle> { + fn append_processing_instruction_to_doc( + &self, + target: StrTendril, + data: StrTendril, + ) -> ProcessResult<Handle> { let pi = self.sink.create_pi(target, data); self.sink.append(&self.doc_handle, AppendNode(pi)); ProcessResult::Done } - fn append_processing_instruction_to_html(&self, target: StrTendril, data: StrTendril) -> ProcessResult<Handle> { + fn append_processing_instruction_to_html( + &self, + target: StrTendril, + data: StrTendril, + ) -> ProcessResult<Handle> { let open_elems = self.open_elems.borrow(); let el_target = html_elem(&open_elems); let pi = self.sink.create_pi(target, data); diff --git a/html5ever/src/tree_builder/rules.rs b/html5ever/src/tree_builder/rules.rs index ba75abee..ad1a5164 100644 --- a/html5ever/src/tree_builder/rules.rs +++ b/html5ever/src/tree_builder/rules.rs @@ -104,7 +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::ProcessingInstruction(target, data) => { + self.append_processing_instruction_to_doc(target, data) + }, token => { if !self.opts.iframe_srcdoc { self.unexpected(&token); @@ -125,7 +127,9 @@ 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::ProcessingInstruction(target, data) => { + self.append_processing_instruction_to_doc(target, data) + }, Token::Characters(SplitStatus::NotSplit, text) => { ProcessResult::SplitWhitespace(text) @@ -158,7 +162,9 @@ where }, Token::Characters(SplitStatus::Whitespace, _) => ProcessResult::Done, Token::Comment(text) => self.append_comment(text), - Token::ProcessingInstruction(target, data) => self.append_processing_instruction_to_doc(target, data), + Token::ProcessingInstruction(target, data) => { + self.append_processing_instruction_to_doc(target, data) + }, Token::Tag(tag!(<html>)) => self.step(InsertionMode::InBody, token), @@ -190,7 +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_to_doc(target, data), + Token::ProcessingInstruction(target, data) => { + self.append_processing_instruction_to_doc(target, data) + }, Token::Tag(tag!(<html>)) => self.step(InsertionMode::InBody, token), @@ -343,7 +351,9 @@ where }, Token::Comment(_) => self.step(InsertionMode::InHead, token), - Token::ProcessingInstruction(target, data) => self.append_processing_instruction_to_doc(target, data), + Token::ProcessingInstruction(target, data) => { + self.append_processing_instruction_to_doc(target, data) + }, Token::Tag( tag!(<basefont> | <bgsound> | <link> | <meta> | <noframes> | <style>), @@ -371,7 +381,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_to_doc(target, data), + Token::ProcessingInstruction(target, data) => { + self.append_processing_instruction_to_doc(target, data) + }, Token::Tag(tag!(<html>)) => self.step(InsertionMode::InBody, token), @@ -431,7 +443,9 @@ where Token::Comment(text) => self.append_comment(text), - Token::ProcessingInstruction(target, data) => self.append_processing_instruction(target, data), + Token::ProcessingInstruction(target, data) => { + self.append_processing_instruction(target, data) + }, Token::Tag(tag @ tag!(<html>)) => { self.unexpected(&tag); @@ -1047,8 +1061,10 @@ where Token::NullCharacter | Token::Characters(..) => self.process_chars_in_table(token), Token::Comment(text) => self.append_comment(text), - - Token::ProcessingInstruction(target, data) => self.append_processing_instruction(target, data), + + Token::ProcessingInstruction(target, data) => { + self.append_processing_instruction(target, data) + }, Token::Tag(tag @ tag!(<caption>)) => { self.pop_until_current(table_scope); @@ -1223,7 +1239,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_to_doc(target, data), + Token::ProcessingInstruction(target, data) => { + self.append_processing_instruction_to_doc(target, data) + }, Token::Tag(tag!(<html>)) => self.step(InsertionMode::InBody, token), @@ -1495,7 +1513,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::ProcessingInstruction(target, data) => { + self.append_processing_instruction_to_html(target, data) + }, Token::Tag(tag!(<html>)) => self.step(InsertionMode::InBody, token), @@ -1524,7 +1544,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::ProcessingInstruction(target, data) => { + self.append_processing_instruction(target, data) + }, Token::Tag(tag!(<html>)) => self.step(InsertionMode::InBody, token), @@ -1571,7 +1593,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::ProcessingInstruction(target, data) => { + self.append_processing_instruction(target, data) + }, Token::Tag(tag!(<html>)) => self.step(InsertionMode::InBody, token), @@ -1597,7 +1621,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::ProcessingInstruction(target, data) => { + self.append_processing_instruction_to_doc(target, data) + }, Token::Tag(tag!(<html>)) => self.step(InsertionMode::InBody, token), @@ -1619,7 +1645,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::ProcessingInstruction(target, data) => { + self.append_processing_instruction_to_doc(target, data) + }, Token::Tag(tag!(<html>)) => self.step(InsertionMode::InBody, token), @@ -1650,7 +1678,9 @@ where Token::Comment(text) => self.append_comment(text), - Token::ProcessingInstruction(target, data) => self.append_processing_instruction(target, data), + Token::ProcessingInstruction(target, data) => { + self.append_processing_instruction(target, data) + }, Token::Tag( tag @ diff --git a/rcdom/tests/html-serializer.rs b/rcdom/tests/html-serializer.rs index 0e39699e..3122080e 100644 --- a/rcdom/tests/html-serializer.rs +++ b/rcdom/tests/html-serializer.rs @@ -246,23 +246,11 @@ 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_1, r#"<?target>"#, r#"<?target ?>"#); -test!( - processing_instruction_2, - r#"<?target?>"#, - r#"<?target ?>"# -); +test!(processing_instruction_2, r#"<?target?>"#, r#"<?target ?>"#); -test!( - processing_instruction_3, - r#"<?target >"#, - r#"<?target ?>"# -); +test!(processing_instruction_3, r#"<?target >"#, r#"<?target ?>"#); test!( processing_instruction_4, @@ -278,7 +266,6 @@ test!( test_no_parse!(malformed_tokens, r#"foo</div><div>"#); - #[test] fn doctype() { let dom = parse_document(RcDom::default(), ParseOpts::default()).one("<!doctype html>"); From b8f0e9d905c9bdac1963f1a96ba0e63aa52655fe Mon Sep 17 00:00:00 2001 From: darkuss <darkussdelta@gmail.com> Date: Mon, 5 Oct 2026 21:13:31 +0200 Subject: [PATCH 14/23] chore: apply suggested fixes --- html5ever/src/tokenizer/mod.rs | 8 ++++---- html5ever/src/tree_builder/mod.rs | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/html5ever/src/tokenizer/mod.rs b/html5ever/src/tokenizer/mod.rs index aa0b10eb..4d0d3c17 100644 --- a/html5ever/src/tokenizer/mod.rs +++ b/html5ever/src/tokenizer/mod.rs @@ -638,13 +638,13 @@ impl<Sink: TokenSink> Tokenizer<Sink> { 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 - let buf = mem::take(&mut *self.temp_buf.borrow_mut()); - comment.push_tendril(&buf); + comment.push_tendril(&mem::take(&mut *self.temp_buf.borrow_mut())); } fn emit_current_processing_instruction(&self) { - let pi = self.current_processing_instruction.take(); - self.process_token_and_continue(ProcessingInstructionToken(pi)); + self.process_token_and_continue( + ProcessingInstructionToken(self.current_processing_instruction.take()) + ); } } //§ END diff --git a/html5ever/src/tree_builder/mod.rs b/html5ever/src/tree_builder/mod.rs index 4f26f387..f42debc9 100644 --- a/html5ever/src/tree_builder/mod.rs +++ b/html5ever/src/tree_builder/mod.rs @@ -1370,10 +1370,10 @@ where target: StrTendril, data: StrTendril, ) -> ProcessResult<Handle> { - let open_elems = self.open_elems.borrow(); - let el_target = html_elem(&open_elems); + let open_elements = self.open_elems.borrow(); + let element_target = html_elem(&open_elements); let pi = self.sink.create_pi(target, data); - self.sink.append(el_target, AppendNode(pi)); + self.sink.append(element_target, AppendNode(pi)); ProcessResult::Done } From 09c54879d027c738970b3baa2f0ad1dbf5df12fa Mon Sep 17 00:00:00 2001 From: darkuss <darkussdelta@gmail.com> Date: Mon, 5 Oct 2026 21:17:13 +0200 Subject: [PATCH 15/23] chore: replace remaining uses of `pi` with `processing_instruction` --- html5ever/src/tree_builder/mod.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/html5ever/src/tree_builder/mod.rs b/html5ever/src/tree_builder/mod.rs index f42debc9..006d4c76 100644 --- a/html5ever/src/tree_builder/mod.rs +++ b/html5ever/src/tree_builder/mod.rs @@ -1350,8 +1350,8 @@ where target: StrTendril, data: StrTendril, ) -> ProcessResult<Handle> { - let pi = self.sink.create_pi(target, data); - self.insert_appropriately(AppendNode(pi), None); + let processing_instruction = self.sink.create_pi(target, data); + self.insert_appropriately(AppendNode(processing_instruction), None); ProcessResult::Done } @@ -1360,8 +1360,8 @@ where target: StrTendril, data: StrTendril, ) -> ProcessResult<Handle> { - let pi = self.sink.create_pi(target, data); - self.sink.append(&self.doc_handle, AppendNode(pi)); + let processing_instruction = self.sink.create_pi(target, data); + self.sink.append(&self.doc_handle, AppendNode(processing_instruction)); ProcessResult::Done } @@ -1372,8 +1372,8 @@ where ) -> ProcessResult<Handle> { let open_elements = self.open_elems.borrow(); let element_target = html_elem(&open_elements); - let pi = self.sink.create_pi(target, data); - self.sink.append(element_target, AppendNode(pi)); + let processing_instruction = self.sink.create_pi(target, data); + self.sink.append(element_target, AppendNode(processing_instruction)); ProcessResult::Done } From 000588b282e04da34d195fe53973dd070e2e8270 Mon Sep 17 00:00:00 2001 From: darkuss <darkussdelta@gmail.com> Date: Mon, 5 Oct 2026 21:25:16 +0200 Subject: [PATCH 16/23] chore: run `cargo fmt` --- html5ever/src/tokenizer/mod.rs | 6 +++--- html5ever/src/tree_builder/mod.rs | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/html5ever/src/tokenizer/mod.rs b/html5ever/src/tokenizer/mod.rs index 4d0d3c17..dfae01e1 100644 --- a/html5ever/src/tokenizer/mod.rs +++ b/html5ever/src/tokenizer/mod.rs @@ -642,9 +642,9 @@ impl<Sink: TokenSink> Tokenizer<Sink> { } fn emit_current_processing_instruction(&self) { - self.process_token_and_continue( - ProcessingInstructionToken(self.current_processing_instruction.take()) - ); + self.process_token_and_continue(ProcessingInstructionToken( + self.current_processing_instruction.take(), + )); } } //§ END diff --git a/html5ever/src/tree_builder/mod.rs b/html5ever/src/tree_builder/mod.rs index 006d4c76..ca19b6ad 100644 --- a/html5ever/src/tree_builder/mod.rs +++ b/html5ever/src/tree_builder/mod.rs @@ -1361,7 +1361,8 @@ where data: StrTendril, ) -> ProcessResult<Handle> { let processing_instruction = self.sink.create_pi(target, data); - self.sink.append(&self.doc_handle, AppendNode(processing_instruction)); + self.sink + .append(&self.doc_handle, AppendNode(processing_instruction)); ProcessResult::Done } @@ -1373,7 +1374,8 @@ where 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)); + self.sink + .append(element_target, AppendNode(processing_instruction)); ProcessResult::Done } From f91049f8b9ffb562d7b6dcb8e0543d543cb65ede Mon Sep 17 00:00:00 2001 From: darkuss <darkussdelta@gmail.com> Date: Thu, 8 Oct 2026 11:58:45 +0200 Subject: [PATCH 17/23] apply fixes --- html5ever/src/tokenizer/interface.rs | 4 ++-- html5ever/src/tokenizer/mod.rs | 18 ++++++++++-------- html5ever/src/tree_builder/rules.rs | 12 +++++------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/html5ever/src/tokenizer/interface.rs b/html5ever/src/tokenizer/interface.rs index f1029000..14e1f6a1 100644 --- a/html5ever/src/tokenizer/interface.rs +++ b/html5ever/src/tokenizer/interface.rs @@ -81,7 +81,7 @@ impl Tag { } } -/// A processing instruction token +/// A processing instruction token. #[derive(PartialEq, Eq, Clone, Debug, Default)] pub struct ProcessingInstruction { pub target: StrTendril, @@ -96,7 +96,7 @@ pub enum Token { TagToken(Tag), /// A comment like `<!-- foo -->`. CommentToken(StrTendril), - /// A processing instruction like `<?target data ?>` + /// A processing instruction like `<?target data ?>`. ProcessingInstructionToken(ProcessingInstruction), /// A sequence of characters. CharacterTokens(StrTendril), diff --git a/html5ever/src/tokenizer/mod.rs b/html5ever/src/tokenizer/mod.rs index dfae01e1..08c0ca5b 100644 --- a/html5ever/src/tokenizer/mod.rs +++ b/html5ever/src/tokenizer/mod.rs @@ -2679,7 +2679,7 @@ impl<Sink: TokenSink> Tokenizer<Sink> { states::ProcessingInstructionOpen => loop { match get_char!(self, input) { // ↪ ASCII alpha - // ↪ u+005F LOW LINE (_) + // ↪ U+005F LOW LINE (_) character if character.is_ascii_alphabetic() || character == '_' => { // Reconsume in the processing instruction target state. go!(self: reconsume State::ProcessingInstructionTarget); @@ -2706,11 +2706,13 @@ impl<Sink: TokenSink> Tokenizer<Sink> { // ↪ 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 target = self.temp_buf.borrow(); + 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 target.to_lowercase() == "xml" - || target.to_lowercase() == "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. @@ -2718,7 +2720,6 @@ impl<Sink: TokenSink> Tokenizer<Sink> { self.convert_to_comment(); go!(self: reconsume BogusComment); } else { - drop(target); 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. @@ -2743,7 +2744,7 @@ impl<Sink: TokenSink> Tokenizer<Sink> { }, // ↪ Anything else _ => { - // This is an invalid-first-character-of-processing-instruction-target parse error. + // 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(); @@ -2814,7 +2815,8 @@ impl<Sink: TokenSink> Tokenizer<Sink> { go!(self: reconsume ProcessingInstructionData); }, } - }, //§ END + }, + //§ END } } diff --git a/html5ever/src/tree_builder/rules.rs b/html5ever/src/tree_builder/rules.rs index ad1a5164..5cb14c07 100644 --- a/html5ever/src/tree_builder/rules.rs +++ b/html5ever/src/tree_builder/rules.rs @@ -163,7 +163,7 @@ where Token::Characters(SplitStatus::Whitespace, _) => ProcessResult::Done, Token::Comment(text) => self.append_comment(text), Token::ProcessingInstruction(target, data) => { - self.append_processing_instruction_to_doc(target, data) + self.append_processing_instruction(target, data) }, Token::Tag(tag!(<html>)) => self.step(InsertionMode::InBody, token), @@ -197,7 +197,7 @@ 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_to_doc(target, data) + self.append_processing_instruction(target, data) }, Token::Tag(tag!(<html>)) => self.step(InsertionMode::InBody, token), @@ -351,9 +351,7 @@ where }, Token::Comment(_) => self.step(InsertionMode::InHead, token), - Token::ProcessingInstruction(target, data) => { - self.append_processing_instruction_to_doc(target, data) - }, + Token::ProcessingInstruction(_, _) => self.step(InsertionMode::InHead, token), Token::Tag( tag!(<basefont> | <bgsound> | <link> | <meta> | <noframes> | <style>), @@ -382,7 +380,7 @@ 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_to_doc(target, data) + self.append_processing_instruction(target, data) }, Token::Tag(tag!(<html>)) => self.step(InsertionMode::InBody, token), @@ -1240,7 +1238,7 @@ 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_to_doc(target, data) + self.append_processing_instruction(target, data) }, Token::Tag(tag!(<html>)) => self.step(InsertionMode::InBody, token), From 9a24f0144e8bd7bc08f948b52bae20f149f1a14c Mon Sep 17 00:00:00 2001 From: darkuss <darkussdelta@gmail.com> Date: Thu, 8 Oct 2026 14:36:17 +0200 Subject: [PATCH 18/23] fix: change processing instruction branches to be functional in rcdom example and tests --- rcdom/examples/print-rcdom.rs | 11 ++++++++++- rcdom/tests/html-tree-builder.rs | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) 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/tests/html-tree-builder.rs b/rcdom/tests/html-tree-builder.rs index 7473d4a9..cdc65214 100644 --- a/rcdom/tests/html-tree-builder.rs +++ b/rcdom/tests/html-tree-builder.rs @@ -138,7 +138,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_str(" "); + buf.push_str(contents); + buf.push_str("?>\n"); + }, } for child in node.children.borrow().iter() { From 13f02ee71454193b3ae5cb7033e9d8f53f5508ec Mon Sep 17 00:00:00 2001 From: Delta-official <64544951+Delta-official@users.noreply.github.com> Date: Wed, 28 Oct 2026 15:59:17 +0000 Subject: [PATCH 19/23] Update tree construction tests from web-platform-tests/wpt https://github.com/web-platform-tests/wpt/commits/4aa56d3beafc5655fa55491169eb14845b44eab3/html/syntax/parsing/resources --- rcdom/data/test/wpt-commit.txt | 2 +- rcdom/wpt-tree-construction-tests/README.md | 112 ++ .../adoption-agency-reparenting.js | 32 + .../adoption02.dat | 33 + .../comments01.dat | 9 +- .../html5test-com.dat | 72 +- .../plain-text-unsafe.dat | Bin 9486 -> 14406 bytes .../processing-instructions.dat | 1132 +++++++++++++++++ .../scripted_foster01.dat | 21 + .../search-element.dat | 86 ++ .../wpt-tree-construction-tests/template.dat | 206 +++ rcdom/wpt-tree-construction-tests/test.js | 12 +- rcdom/wpt-tree-construction-tests/tests1.dat | 17 +- rcdom/wpt-tree-construction-tests/tests19.dat | 58 + rcdom/wpt-tree-construction-tests/tests4.dat | 6 + .../tests_innerHTML_1.dat | 2 +- .../void-in-phrasing.dat | 151 +++ .../wpt-tree-construction-tests/webkit02.dat | 45 + 18 files changed, 1969 insertions(+), 27 deletions(-) create mode 100644 rcdom/wpt-tree-construction-tests/README.md create mode 100644 rcdom/wpt-tree-construction-tests/adoption-agency-reparenting.js create mode 100644 rcdom/wpt-tree-construction-tests/processing-instructions.dat create mode 100644 rcdom/wpt-tree-construction-tests/scripted_foster01.dat create mode 100644 rcdom/wpt-tree-construction-tests/void-in-phrasing.dat 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/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 e904eff0b73aab1f2611501a76bb865e4b086d60..87a909f0bb7dd5088cb0bb3929bf142e0204be85 100644 GIT binary patch delta 1899 zcmb7FO-~a+7;dYyvJohPu$%HRZV^FU>9z$4)+Pic#8lA;i3#ap+D_Y*c6Z$!Nl8eI z-t<5;?~TM?U`(1AkLb;df53|-Ts7*!vxzfpVcUwu?xC|g)8}KJ_ubj;8z0Q_C-D)n z)0SpZ&CrF_3n6x)TdRo#(sYE;!nOI8d1R9`U*=O;!y;NvM`=T+M5icY5F6<RW&fcl zYvCecH;S>2sDWfYZ>-BgFoP);V)jNZ9y_yE;aqbilkwOTn}T2Byjz9&V-iHAR2yzE zMOa5mD>u1UN^%yim^2Oc)V{CU#$b2YH`HXZwzQnO&vJn8;u1XfOP-l&a1R9da93K$ zH-xyjxOffWEF~6dO0+pX7MA@#vAM>BCC+*Ueu#_kW#GCe5@PZqjCy;(6jMt--|xx- z3%bFFQ_QLvj0(iI6`E(c*}RIHjo83Sn&Gug8JSHe%Yz|)6UQ-EN(d6mGAvt|P%nlf zlXHlaOqK!3C=}-uomIQC0(;#O>~s!*zo!$v`FfOabdnKn;DVM>vYKU6C7s6>W=Kmh zvi0D(a1<VoC9#ZSsa6{}q#Ik--`QEM`=C7B-+fS6>`En*@LQa9Ps0np=!r~&dg?4J z_(Jeb^n+(~1YXHqZ$69aNtVco<3&vKfV&sqV@DYLgMF-F*`C?&ogs-od(>G*5P?hH z;f@J)PL09?F#+XZA3W;~RMD@6aoF*m_e9jHV)IbdpQ?d+;ib?u$YtX(tg{!X(%ed^ zSctnypm$$(M_^BuSSOx_kSN02&Zs9Gsi{h<O%P!V?O!tMlu{+>$~$?O0wQ|a$Y^@* zs!U0VPUUH_AamJm?~FTIDfaE5C$Q`bGPBaXe`_7aQ*Xub;mT@-0<m0NZ@=l_t51Qk zj>!>)oh!K_J8cAZTp*KW!fI-yA6BNe;AwB5zZHI|5l=N*AoT=Du8MQ*gJ4<_#vDQ( zA1c~M)0OIWHIrx}XiTt?tf5@3T-C+IcY-Z~>zR&>Dd3p;E24J5Hr;H@_eikhD3^+6 kTc(E`X!R@B7JAe{n+422BE0+BXsvS&K}OrChc-6VAJFD--~a#s delta 12 TcmX?B(C4+`hQ#I_@@6~$DRu>W 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" From 23799b48b36afdc04ab4242e5dfa8d71cc2f3fb1 Mon Sep 17 00:00:00 2001 From: darkuss <darkussdelta@gmail.com> Date: Wed, 28 Oct 2026 16:45:11 +0100 Subject: [PATCH 20/23] update html5lib-tests --- rcdom/html5lib-tests | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 8013ec6ae529fa36db1c35c7065a34856e04e8cb Mon Sep 17 00:00:00 2001 From: darkuss <darkussdelta@gmail.com> Date: Wed, 28 Oct 2026 17:07:05 +0100 Subject: [PATCH 21/23] lint: fix lint --- rcdom/tests/html-tree-builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rcdom/tests/html-tree-builder.rs b/rcdom/tests/html-tree-builder.rs index cdc65214..5a3adfa0 100644 --- a/rcdom/tests/html-tree-builder.rs +++ b/rcdom/tests/html-tree-builder.rs @@ -144,7 +144,7 @@ fn serialize(buf: &mut String, indent: usize, handle: Handle) { } => { buf.push_str("<?"); buf.push_str(target); - buf.push_str(" "); + buf.push(' '); buf.push_str(contents); buf.push_str("?>\n"); }, From 7de63f2fb854e0df02e55591067b7245f2409577 Mon Sep 17 00:00:00 2001 From: darkuss <darkussdelta@gmail.com> Date: Wed, 28 Oct 2026 18:44:45 +0100 Subject: [PATCH 22/23] feat: add support for #description fields in tree builder tests --- rcdom/tests/html-tree-builder.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/rcdom/tests/html-tree-builder.rs b/rcdom/tests/html-tree-builder.rs index 5a3adfa0..b648f457 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 { @@ -205,14 +212,23 @@ 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 { From 06778a3082c0e53403e00aa3111132adee3ef987 Mon Sep 17 00:00:00 2001 From: darkuss <darkussdelta@gmail.com> Date: Wed, 28 Oct 2026 18:47:19 +0100 Subject: [PATCH 23/23] run rustfmt and fix clippy warnings --- rcdom/tests/html-tree-builder.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/rcdom/tests/html-tree-builder.rs b/rcdom/tests/html-tree-builder.rs index b648f457..0227d32b 100644 --- a/rcdom/tests/html-tree-builder.rs +++ b/rcdom/tests/html-tree-builder.rs @@ -215,12 +215,11 @@ fn make_test_desc_with_scripting_flag( let skip = ignores.contains(name); let mut name = name.to_owned(); - let description = fields - .get("description"); + let description = fields.get("description"); if let Some(description) = description { name.push_str(": "); - name.push_str(&description.trim_end_matches('\n')); + name.push_str(description.trim_end_matches('\n')); } let mut data = expect_field("data");