Skip to content

Commit

Permalink
Fix incorrect .error_position() when encountering syntax error for …
Browse files Browse the repository at this point in the history
…open or self-closed tag
  • Loading branch information
Mingun committed Jul 4, 2024
1 parent e4b5e12 commit 522389d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

### Bug Fixes

- [#780]: Fixed incorrect `.error_position()` when encountering syntax error for open or self-closed tag.

### Misc Changes

- [#780]: `reader::Parser`, `reader::ElementParser` and `reader::PiParser` moved to the new module `parser`.
Expand Down
12 changes: 8 additions & 4 deletions src/reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,8 @@ macro_rules! read_until_close {
{
Ok((bang_type, bytes)) => $self.state.emit_bang(bang_type, bytes),
Err(e) => {
// <!....EOF
// ^^^^^ - `buf` does not contains `<`, but we want to report error at `<`,
// so we move offset to it (-1 for `<`)
// We want to report error at `<`, but offset was increased,
// so return it back (-1 for `<`)
$self.state.last_error_offset = start - 1;
Err(e)
}
Expand Down Expand Up @@ -388,7 +387,12 @@ macro_rules! read_until_close {
$(.$await)?
{
Ok(bytes) => Ok($self.state.emit_start(bytes)),
Err(e) => Err(e),
Err(e) => {
// We want to report error at `<`, but offset was increased,
// so return it back (-1 for `<`)
$self.state.last_error_offset = start - 1;
Err(e)
}
},
// `<` - syntax error, tag not closed
Ok(None) => {
Expand Down

0 comments on commit 522389d

Please sign in to comment.