mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-06 02:21:45 +00:00
Reject '+' sign in page selection numbers (#5715)
Found while testing crates/ui-egui/src/panels/page_selection_ui.rs:24-27 (parse, `number` closure) Co-authored-by: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4a0b1dd158
commit
d7dd1de647
1 file changed
+10
-1
@@ -22,7 +22,9 @@ pub(crate) fn parse(text: &str, count: usize) -> Result<Vec<usize>, PrintError>
|
||||
let mut pages = BTreeSet::new();
|
||||
let mut budget = 1_000_000usize;
|
||||
let number = |token: &str| {
|
||||
let n = token.trim().parse::<usize>().map_err(|_| PrintError::NotAPage(token.into()))?;
|
||||
let t = token.trim();
|
||||
let n =
|
||||
if t.bytes().all(|b| b.is_ascii_digit()) { t.parse::<usize>().ok() } else { None }.ok_or_else(|| PrintError::NotAPage(token.into()))?;
|
||||
if n == 0 || n > count { Err(PrintError::OutOfRange(n, count)) } else { Ok(n - 1) }
|
||||
};
|
||||
for part in text.split([',', ';']).map(str::trim) {
|
||||
@@ -132,6 +134,13 @@ impl PageSelectionInput {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn plus_sign_is_not_a_page_number() {
|
||||
for text in ["+3", "+2-4", "2-+4"] {
|
||||
assert!(matches!(parse(text, 100), Err(PrintError::NotAPage(_))), "{text}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn selection_ranges_are_sorted_unique_and_bounded() {
|
||||
let pages = parse("1,12,16-18,89,92,93,97,99", 100).unwrap();
|
||||
|
||||
Reference in new issue
Block a user