Use written tag name for comparison

This commit is contained in:
Wilson Lin 2021-02-07 01:46:46 +11:00
parent d2408732f5
commit 485db71ca6
3 changed files with 16 additions and 3 deletions

View File

@ -64,6 +64,9 @@ fn maybe_mark_indicator(line: &mut Vec<u8>, marker: u8, maybe_pos: isize, lower:
// Pass -1 for read_pos or write_pos to prevent them from being represented.
pub fn debug_repr(code: &[u8], read_pos: isize, write_pos: isize) -> String {
let only_one_pos = read_pos == -1 || write_pos == -1;
let read_marker = if only_one_pos { b'^' } else { b'R' };
let write_marker = if only_one_pos { b'^' } else { b'W' };
let mut lines = Vec::<(isize, String)>::new();
let mut cur_pos = 0;
for (line_no, line) in code.split(|c| *c == b'\n').enumerate() {
@ -75,8 +78,8 @@ pub fn debug_repr(code: &[u8], read_pos: isize, write_pos: isize) -> String {
// Rust does lazy allocation by default, so this is not wasteful.
let mut indicator_line = Vec::new();
maybe_mark_indicator(&mut indicator_line, b'W', write_pos, cur_pos, new_pos);
let marked_read = maybe_mark_indicator(&mut indicator_line, b'R', read_pos, cur_pos, new_pos);
maybe_mark_indicator(&mut indicator_line, write_marker, write_pos, cur_pos, new_pos);
let marked_read = maybe_mark_indicator(&mut indicator_line, read_marker, read_pos, cur_pos, new_pos);
if !indicator_line.is_empty() {
lines.push((-1, unsafe { String::from_utf8_unchecked(indicator_line) }));
};

View File

@ -108,6 +108,16 @@ fn test_no_whitespace_minification() {
</code></pre>"#);
}
#[test]
fn test_root_closing_tag_omission() {
eval(b"<html></html>", b"<html>");
eval(b"<html>\n</html>", b"<html>");
eval(b" <html>\n</html>", b"<html>");
eval(b"<html>", b"<html>");
eval(b" <html>\n", b"<html>");
eval(b" <!doctype html> <html>\n", b"<!doctype html><html>");
}
#[test]
fn test_self_closing_svg_tag_whitespace_removal() {
eval(b"<svg><path d=a /></svg>", b"<svg><path d=a /></svg>");

View File

@ -216,7 +216,7 @@ pub fn process_tag(
_ => closing_tag_omitted = process_content(proc, cfg, child_ns, Some(tag_name), descendant_of_pre)?.closing_tag_omitted,
};
let can_omit_closing_tag = can_omit_as_last_node(proc, parent, source_tag_name);
let can_omit_closing_tag = can_omit_as_last_node(proc, parent, tag_name);
if closing_tag_omitted || proc.at_end() && can_omit_closing_tag {
return Ok(MaybeClosingTag(None));
};