From 79674b537e84d407278396681b41eff9a17c2f6d Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Thu, 25 Sep 2025 16:31:54 +0900 Subject: [PATCH] Enable checking for orphan s A follow-up to adb2e6fb0121065b879ef6c69a70703f02e88651, now that https://github.com/whatwg/html/pull/11392 is merged. --- src/variables.rs | 57 ++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/src/variables.rs b/src/variables.rs index 21804210..32e08d72 100644 --- a/src/variables.rs +++ b/src/variables.rs @@ -1,9 +1,6 @@ //! Converts custom attributes `algorithm=""` and `var-scope=""` to `data-` -//! equivalents, to preserve validity of the output document. -// -// TODO: error on ``s outside of those scopes, unless the `` has an -// `ignore=""` attribute. (This code is present but disabled until -// https://github.com/whatwg/html/pull/11392 is merged.) +//! equivalents, to preserve validity of the output document. Errors on ``s +//! outside of those scopes, unless the `` has an `ignore=""` attribute. // // TODO: check for ``s inside of these scopes that are only used once, and // error when such lone ``s are encountered. @@ -183,13 +180,12 @@ impl<'a> Processor<'a> { return Err(io::Error::new(io::ErrorKind::InvalidData, msgs.join("\n"))); } - // Disabled until https://github.com/whatwg/html/pull/11392 is merged. - // if !self.var_out_of_scope_msgs.is_empty() { - // return Err(io::Error::new( - // io::ErrorKind::InvalidData, - // self.var_out_of_scope_msgs.join("\n"), - // )); - // } + if !self.var_out_of_scope_msgs.is_empty() { + return Err(io::Error::new( + io::ErrorKind::InvalidData, + self.var_out_of_scope_msgs.join("\n"), + )); + } let old_algorithm = QualName::new(None, ns!(), LocalName::from("algorithm")); let new_algorithm = QualName::new(None, ns!(), LocalName::from("data-algorithm")); @@ -329,25 +325,24 @@ mod tests { ); } - // Disabled until https://github.com/whatwg/html/pull/11392 is merged. - // #[tokio::test] - // async fn test_var_outside_scope_errors() { - // let parsed = parse_document_async( - // r##" - //

Outside scope bar

- // "## - // .as_bytes(), - // ) - // .await - // .unwrap(); - // let document = parsed.document().clone(); - - // let mut proc = Processor::new(&parsed); - // dom_utils::scan_dom(&document, &mut |h| proc.visit(h)); - // let result = proc.apply(); - // let err = result.unwrap_err(); - // assert!(err.to_string().contains("Line 2: ")); - // } + #[tokio::test] + async fn test_var_outside_scope_errors() { + let parsed = parse_document_async( + r##" +

Outside scope bar

+ "## + .as_bytes(), + ) + .await + .unwrap(); + let document = parsed.document().clone(); + + let mut proc = Processor::new(&parsed); + dom_utils::scan_dom(&document, &mut |h| proc.visit(h)); + let result = proc.apply(); + let err = result.unwrap_err(); + assert!(err.to_string().contains("Line 2: ")); + } #[tokio::test] async fn test_var_inside_algorithm_ok() {