Skip to content

Commit 0af3f35

Browse files
committed
Enable checking for orphan <var>s
A follow-up to adb2e6f, now that whatwg/html#11392 is merged.
1 parent 6a20151 commit 0af3f35

File tree

1 file changed

+26
-31
lines changed

1 file changed

+26
-31
lines changed

src/variables.rs

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
//! Converts custom attributes `algorithm=""` and `var-scope=""` to `data-`
2-
//! equivalents, to preserve validity of the output document.
3-
//
4-
// TODO: error on `<var>`s outside of those scopes, unless the `<var>` has an
5-
// `ignore=""` attribute. (This code is present but disabled until
6-
// https://github.com/whatwg/html/pull/11392 is merged.)
2+
//! equivalents, to preserve validity of the output document. Errors on `<var>`s
3+
//! outside of those scopes, unless the `<var>` has an `ignore=""` attribute.
74
//
85
// TODO: check for `<var>`s inside of these scopes that are only used once, and
96
// error when such lone `<var>`s are encountered.
@@ -183,13 +180,12 @@ impl<'a> Processor<'a> {
183180
return Err(io::Error::new(io::ErrorKind::InvalidData, msgs.join("\n")));
184181
}
185182

186-
// Disabled until https://github.com/whatwg/html/pull/11392 is merged.
187-
// if !self.var_out_of_scope_msgs.is_empty() {
188-
// return Err(io::Error::new(
189-
// io::ErrorKind::InvalidData,
190-
// self.var_out_of_scope_msgs.join("\n"),
191-
// ));
192-
// }
183+
if !self.var_out_of_scope_msgs.is_empty() {
184+
return Err(io::Error::new(
185+
io::ErrorKind::InvalidData,
186+
self.var_out_of_scope_msgs.join("\n"),
187+
));
188+
}
193189

194190
let old_algorithm = QualName::new(None, ns!(), LocalName::from("algorithm"));
195191
let new_algorithm = QualName::new(None, ns!(), LocalName::from("data-algorithm"));
@@ -329,25 +325,24 @@ mod tests {
329325
);
330326
}
331327

332-
// Disabled until https://github.com/whatwg/html/pull/11392 is merged.
333-
// #[tokio::test]
334-
// async fn test_var_outside_scope_errors() {
335-
// let parsed = parse_document_async(
336-
// r##"<!DOCTYPE html>
337-
// <p>Outside scope <var>bar</var></p>
338-
// "##
339-
// .as_bytes(),
340-
// )
341-
// .await
342-
// .unwrap();
343-
// let document = parsed.document().clone();
344-
345-
// let mut proc = Processor::new(&parsed);
346-
// dom_utils::scan_dom(&document, &mut |h| proc.visit(h));
347-
// let result = proc.apply();
348-
// let err = result.unwrap_err();
349-
// assert!(err.to_string().contains("Line 2: "));
350-
// }
328+
#[tokio::test]
329+
async fn test_var_outside_scope_errors() {
330+
let parsed = parse_document_async(
331+
r##"<!DOCTYPE html>
332+
<p>Outside scope <var>bar</var></p>
333+
"##
334+
.as_bytes(),
335+
)
336+
.await
337+
.unwrap();
338+
let document = parsed.document().clone();
339+
340+
let mut proc = Processor::new(&parsed);
341+
dom_utils::scan_dom(&document, &mut |h| proc.visit(h));
342+
let result = proc.apply();
343+
let err = result.unwrap_err();
344+
assert!(err.to_string().contains("Line 2: "));
345+
}
351346

352347
#[tokio::test]
353348
async fn test_var_inside_algorithm_ok() {

0 commit comments

Comments
 (0)