diff --git a/src/err.rs b/src/err.rs index 2a8c753..6c10db7 100644 --- a/src/err.rs +++ b/src/err.rs @@ -64,6 +64,9 @@ fn maybe_mark_indicator(line: &mut Vec, 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) })); }; diff --git a/src/tests/mod.rs b/src/tests/mod.rs index ee5d63a..009257f 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -108,6 +108,16 @@ fn test_no_whitespace_minification() { "#); } +#[test] +fn test_root_closing_tag_omission() { + eval(b"", b""); + eval(b"\n", b""); + eval(b" \n", b""); + eval(b"", b""); + eval(b" \n", b""); + eval(b" \n", b""); +} + #[test] fn test_self_closing_svg_tag_whitespace_removal() { eval(b"", b""); diff --git a/src/unit/tag.rs b/src/unit/tag.rs index a0bb5fd..45290b2 100644 --- a/src/unit/tag.rs +++ b/src/unit/tag.rs @@ -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)); };