Skip to content

Commit

Permalink
Rewrite MissedDoctypeName check to be more obvious
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingun committed Nov 21, 2023
1 parent b20a77e commit 296274b
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/reader/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,19 @@ impl ReaderState {
)))
}
BangType::DocType if uncased_starts_with(buf, b"!DOCTYPE") => {
let start = buf[8..]
.iter()
.position(|b| !is_whitespace(*b))
.unwrap_or(len - 8);
if start + 8 >= len {
// Because we here, we at least read `<!DOCTYPE>` and offset after `>`.
// We want report error at place where name is expected - this is just
// before `>`
self.offset -= 1;
return Err(Error::IllFormed(IllFormedError::MissedDoctypeName));
match buf[8..].iter().position(|&b| !is_whitespace(b)) {
Some(start) => Ok(Event::DocType(BytesText::wrap(
&buf[8 + start..],
self.decoder(),
))),
None => {
// Because we here, we at least read `<!DOCTYPE>` and offset after `>`.
// We want report error at place where name is expected - this is just
// before `>`
self.offset -= 1;
return Err(Error::IllFormed(IllFormedError::MissedDoctypeName));
}
}
Ok(Event::DocType(BytesText::wrap(
&buf[8 + start..],
self.decoder(),
)))
}
_ => {
// <!....
Expand Down

0 comments on commit 296274b

Please sign in to comment.