aboutsummaryrefslogtreecommitdiff
path: root/src/tokenizer
diff options
context:
space:
mode:
Diffstat (limited to 'src/tokenizer')
-rw-r--r--src/tokenizer/machine.rs55
1 files changed, 27 insertions, 28 deletions
diff --git a/src/tokenizer/machine.rs b/src/tokenizer/machine.rs
index b6291b5..ff72a7c 100644
--- a/src/tokenizer/machine.rs
+++ b/src/tokenizer/machine.rs
@@ -1801,39 +1801,38 @@ where
State::NamedCharacterReference => {
let first_char = slf.read_char()?.unwrap(); // unwrap cannot panic since we just unread the char
- let char_ref =
- try_read_character_reference(first_char, |x| slf.try_read_string(x, true))?;
-
- if let Some(char_ref) = char_ref {
- slf.temporary_buffer.push(first_char);
- slf.temporary_buffer.push_str(char_ref.name);
- let char_ref_name_last_character = char_ref.name.chars().last();
+ let Some(char_ref) =
+ try_read_character_reference(first_char, |x| slf.try_read_string(x, true))?
+ else {
+ slf.unread_char(Some(first_char));
+ slf.flush_code_points_consumed_as_character_reference();
+ slf.state = State::AmbiguousAmpersand;
+ return Ok(ControlToken::Continue);
+ };
- let next_character = slf.read_char()?;
- slf.unread_char(next_character);
+ slf.temporary_buffer.push(first_char);
+ slf.temporary_buffer.push_str(char_ref.name);
+ let char_ref_name_last_character = char_ref.name.chars().last();
- if slf.is_consumed_as_part_of_an_attribute()
- && char_ref_name_last_character != Some(';')
- && matches!(next_character, Some(x) if x == '=' || x.is_ascii_alphanumeric())
- {
- slf.flush_code_points_consumed_as_character_reference();
- slf.state = slf.return_state.take().unwrap();
- Ok(ControlToken::Continue)
- } else {
- if char_ref_name_last_character != Some(';') {
- slf.emit_error(Error::MissingSemicolonAfterCharacterReference);
- }
+ let next_character = slf.read_char()?;
+ slf.unread_char(next_character);
- slf.temporary_buffer.clear();
- slf.temporary_buffer.push_str(char_ref.characters);
- slf.flush_code_points_consumed_as_character_reference();
- slf.state = slf.return_state.take().unwrap();
- Ok(ControlToken::Continue)
- }
+ if slf.is_consumed_as_part_of_an_attribute()
+ && char_ref_name_last_character != Some(';')
+ && matches!(next_character, Some(x) if x == '=' || x.is_ascii_alphanumeric())
+ {
+ slf.flush_code_points_consumed_as_character_reference();
+ slf.state = slf.return_state.take().unwrap();
+ Ok(ControlToken::Continue)
} else {
- slf.unread_char(Some(first_char));
+ if char_ref_name_last_character != Some(';') {
+ slf.emit_error(Error::MissingSemicolonAfterCharacterReference);
+ }
+
+ slf.temporary_buffer.clear();
+ slf.temporary_buffer.push_str(char_ref.characters);
slf.flush_code_points_consumed_as_character_reference();
- slf.state = State::AmbiguousAmpersand;
+ slf.state = slf.return_state.take().unwrap();
Ok(ControlToken::Continue)
}
}