|
1 | 1 | //! 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. |
7 | 4 | // |
8 | 5 | // TODO: check for `<var>`s inside of these scopes that are only used once, and |
9 | 6 | // error when such lone `<var>`s are encountered. |
@@ -183,13 +180,12 @@ impl<'a> Processor<'a> { |
183 | 180 | return Err(io::Error::new(io::ErrorKind::InvalidData, msgs.join("\n"))); |
184 | 181 | } |
185 | 182 |
|
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 | + } |
193 | 189 |
|
194 | 190 | let old_algorithm = QualName::new(None, ns!(), LocalName::from("algorithm")); |
195 | 191 | let new_algorithm = QualName::new(None, ns!(), LocalName::from("data-algorithm")); |
@@ -329,25 +325,24 @@ mod tests { |
329 | 325 | ); |
330 | 326 | } |
331 | 327 |
|
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 | + } |
351 | 346 |
|
352 | 347 | #[tokio::test] |
353 | 348 | async fn test_var_inside_algorithm_ok() { |
|
0 commit comments