Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 26 additions & 31 deletions src/variables.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
//! Converts custom attributes `algorithm=""` and `var-scope=""` to `data-`
//! equivalents, to preserve validity of the output document.
//
// TODO: error on `<var>`s outside of those scopes, unless the `<var>` 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 `<var>`s
//! outside of those scopes, unless the `<var>` has an `ignore=""` attribute.
//
// TODO: check for `<var>`s inside of these scopes that are only used once, and
// error when such lone `<var>`s are encountered.
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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##"<!DOCTYPE html>
// <p>Outside scope <var>bar</var></p>
// "##
// .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##"<!DOCTYPE html>
<p>Outside scope <var>bar</var></p>
"##
.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() {
Expand Down
Loading