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:
NetterSilverandClaude Haiku 5.5 authored and GitHub committed 2026-11-02 05:07:42 -05:00
1 parent 4a0b1dd158
commit d7dd1de647
1 file changed
+10 -1
+10 -1
View File
@@ -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();