Skip to content

Commit

Permalink
Fix bug with range parsing
Browse files Browse the repository at this point in the history
Fix bug where all ranges with double and triple hyphen had one element.
  • Loading branch information
reknih committed Mar 7, 2024
1 parent 9b302f9 commit cb28735
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1242,4 +1242,32 @@ Martin}}"#;
Err(TypeError::new(74..74, TypeErrorKind::MissingNumber).into())
);
}

#[test]
#[allow(clippy::single_range_in_vec_init)]
fn test_page_ranges() {
let raw = r#"@article{test,
pages = {1---2},
}
@article{test1,
pages = {2--3},
}
@article{test2,
pages = {1},
}"#;

let bibliography = Bibliography::parse(raw).unwrap();
assert_eq!(
bibliography.get("test").unwrap().pages(),
Ok(PermissiveType::Typed(vec![1..2]))
);
assert_eq!(
bibliography.get("test1").unwrap().pages(),
Ok(PermissiveType::Typed(vec![2..3]))
);
assert_eq!(
bibliography.get("test2").unwrap().pages(),
Ok(PermissiveType::Typed(vec![1..1]))
);
}
}
5 changes: 4 additions & 1 deletion src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,10 @@ impl Type for Vec<Range<u32>> {
let mut s = Scanner::new(&range_candidate);
let start = component(&mut s, span.start)?;
s.eat_whitespace();
if !s.eat_if('-') {

// The double and triple hyphen is converted into en dashes and em
// dashes earlier.
if !s.eat_if(['-', '–', '—']) {
res.push(start..start);
continue;
}
Expand Down

0 comments on commit cb28735

Please sign in to comment.