Skip to content

Commit

Permalink
Use of try_consume_reference always treats failure as fatal, so no ne…
Browse files Browse the repository at this point in the history
…ed to backtrack.
  • Loading branch information
adamreichold committed Jan 14, 2025
1 parent a00c17e commit 251084e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,7 @@ fn parse_next_chunk<'a>(stream: &mut Stream<'a>, entities: &[Entity<'a>]) -> Res
// Check for character/entity references.
if c == b'&' {
let start = stream.pos();
match stream.try_consume_reference() {
match stream.consume_reference() {
Some(Reference::Char(ch)) => Ok(NextChunk::Char(ch)),
Some(Reference::Entity(name)) => entities
.iter()
Expand Down Expand Up @@ -1133,7 +1133,7 @@ fn _normalize_attribute(text: StrSpan, buffer: &mut TextBuffer, ctx: &mut Contex

// Check for character/entity references.
let start = stream.pos();
match stream.try_consume_reference() {
match stream.consume_reference() {
Some(Reference::Char(ch)) => {
for b in CharToBytes::new(ch) {
if ctx.loop_detector.depth > 0 {
Expand Down
16 changes: 1 addition & 15 deletions src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -896,22 +896,8 @@ impl<'input> Stream<'input> {
Ok(())
}

/// Consumes according to: <https://www.w3.org/TR/xml/#NT-Reference>
pub fn try_consume_reference(&mut self) -> Option<Reference<'input>> {
let start = self.pos();

// Consume reference on a substream.
let mut s = self.clone();
let result = s.consume_reference()?;

// If the current data is a reference than advance the current stream
// by number of bytes read by substream.
self.advance(s.pos() - start);
Some(result)
}

#[inline(never)]
fn consume_reference(&mut self) -> Option<Reference<'input>> {
pub fn consume_reference(&mut self) -> Option<Reference<'input>> {
if !self.try_consume_byte(b'&') {
return None;
}
Expand Down

0 comments on commit 251084e

Please sign in to comment.