From 6556106154d7e7cbc7820f223b9baaf49a900449 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Fri, 1 Sep 2023 13:27:46 +0200 Subject: fix!: make set_self_closing encoding-independent --- src/emitter.rs | 9 +++------ src/machine.rs | 3 ++- 2 files changed, 5 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/emitter.rs b/src/emitter.rs index bb12ca4..341d335 100644 --- a/src/emitter.rs +++ b/src/emitter.rs @@ -99,7 +99,7 @@ pub trait Emitter { /// /// If the current token is an end tag, the emitter should emit the /// [`Error::EndTagWithTrailingSolidus`] error. - fn set_self_closing(&mut self, slash_offset: O); + fn set_self_closing(&mut self, slash_span: Range); /// Assuming the _current token_ is a doctype, set its "force quirks" flag to true. /// @@ -339,7 +339,7 @@ impl Emitter for DefaultEmitter { self.emit_token(Token::Doctype(doctype)); } - fn set_self_closing(&mut self, slash_offset: O) { + fn set_self_closing(&mut self, slash_span: Range) { let tag = self.current_token.as_mut().unwrap(); match tag { Token::StartTag(StartTag { @@ -349,10 +349,7 @@ impl Emitter for DefaultEmitter { *self_closing = true; } Token::EndTag(_) => { - self.emit_error( - Error::EndTagWithTrailingSolidus, - slash_offset..slash_offset + 1, - ); + self.emit_error(Error::EndTagWithTrailingSolidus, slash_span); } _ => { debug_assert!(false); diff --git a/src/machine.rs b/src/machine.rs index 4f2d129..5c5c533 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -929,7 +929,8 @@ where State::SelfClosingStartTag => match slf.read_char()? { Some('>') => { slf.emitter.set_self_closing( - slf.position_before_match - slf.reader.len_of_char_in_current_encoding('/'), + slf.position_before_match - slf.reader.len_of_char_in_current_encoding('/') + ..slf.position_before_match, ); slf.state = State::Data; slf.emit_current_tag(); -- cgit v1.2.3