Skip to content

Commit

Permalink
fix(parser): Correctly bind 'char' boundaries
Browse files Browse the repository at this point in the history
Fixes #553
  • Loading branch information
epage committed Aug 1, 2024
1 parent 6b7d999 commit 1754161
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
5 changes: 4 additions & 1 deletion crates/core/src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,10 @@ impl<'a> InvalidLiquidToken<'a> {
let invalid_token_position = invalid_token_span.start_pos();
let (offset_l, offset_c) = invalid_token_position.line_col();
let offset_l = offset_l - 1;
let offset_c = offset_c - 1;
let offset_c = (0..offset_c)
.rev()
.find(|i| invalid_token_position.line_of().is_char_boundary(*i))
.unwrap_or(0);

let end_position = match next_elements.last() {
Some(element) => element.as_span().end_pos(),
Expand Down
20 changes: 17 additions & 3 deletions tests/errors.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
use snapbox::assert_data_eq;
use snapbox::str;

#[test]
#[should_panic]
fn test_fuzz() {
let _ = liquid::ParserBuilder::with_stdlib()
match liquid::ParserBuilder::with_stdlib()
.build()
.unwrap()
.parse("˄{%");
.parse("˄{%")
{
Ok(_) => panic!("should fail"),
Err(err) => assert_data_eq!(err.to_string(), str![[r#"
liquid: --> 1:3
|
1 | {%
| ^---
|
= expected Identifier
"#]]),
}
}

0 comments on commit 1754161

Please sign in to comment.