Skip to content

Commit

Permalink
fix(lib): Fail jekyll sort on non-array
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jun 6, 2024
1 parent 016a851 commit a928cba
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions crates/lib/src/jekyll/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ impl Filter for SortFilter {
let args = self.args.evaluate(runtime)?;

let input: Vec<_> = as_sequence(input).collect();
if input.is_empty() {
return Err(invalid_input("Non-empty array expected"));
}
if args.property.is_some() && !input.iter().all(|v| v.is_object()) {
return Err(invalid_input("Array of objects expected"));
}
Expand Down
2 changes: 1 addition & 1 deletion crates/lib/tests/conformance_jekyll/test_filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod sort_filter {
#[test]
fn raise_exception_when_input_is_nil() {
let input = liquid_core::Value::Nil;
assert!(liquid_core::call_filter!(jekyll::Sort, input).is_ok());
assert!(liquid_core::call_filter!(jekyll::Sort, input).is_err());
}
#[test]
fn return_sorted_numbers() {
Expand Down

0 comments on commit a928cba

Please sign in to comment.