{"record":{"id":"831e46a0587e5f0f","repo":"tonhowtf/omniget","slug":"intervalo-invalido","errorCode":null,"errorMessage":"intervalo invalido: {}","messagePattern":"intervalo invalido: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src-tauri/omniget-core/src/core/tools/pdf.rs","lineNumber":396,"sourceCode":"/// \"1-3, 5, 8-\" → páginas 1-based na ordem dada. Vazio ou \"all\" = todas.\npub fn parse_ranges(spec: &str, total: usize) -> anyhow::Result<Vec<usize>> {\n    let spec = spec.trim();\n    if spec.is_empty() || spec.eq_ignore_ascii_case(\"all\") || spec == \"*\" {\n        return Ok((1..=total).collect());\n    }\n    let mut out = Vec::new();\n    for part in spec\n        .split([',', ' '])\n        .map(str::trim)\n        .filter(|p| !p.is_empty())\n    {\n        if let Some((a, b)) = part.split_once('-') {\n            let a: usize = if a.trim().is_empty() {\n                1\n            } else {\n                a.trim()\n                    .parse()\n                    .map_err(|_| anyhow!(\"intervalo invalido: {}\", part))?\n            };\n            let b: usize = if b.trim().is_empty() {\n                total\n            } else {\n                b.trim()\n                    .parse()\n                    .map_err(|_| anyhow!(\"intervalo invalido: {}\", part))?\n            };\n            if a == 0 || b == 0 || a > total || b > total {\n                return Err(anyhow!(\n                    \"pagina fora do documento ({} paginas): {}\",\n                    total,\n                    part\n                ));\n            }\n            if a <= b {\n                out.extend(a..=b);\n            } else {","sourceCodeStart":378,"sourceCodeEnd":414,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/pdf.rs#L378-L414","documentation":"parse_ranges could not parse the start bound of a range token like '5-' or 'a-b' as an unsigned integer. The offending token is included in the message. This is a user-input validation error inside the PDF page-selection parser.","triggerScenarios":"Calling any page-selection API (split, render, to_text, read_pages, redaction_check, read_raw_chars) with a range string whose left side of '-' is non-numeric, e.g. \"abc-10\", \"2.5-7\", \"-1-5\".","commonSituations":"Users typing ranges with spaces/locale digits, GUI passing unvalidated free-text page selectors, scripts interpolating variables that contain non-numeric junk.","solutions":["Sanitize the range string: trim, accept only digits, '-' and ','","Show the user the expected syntax (e.g. \"1-3,5,8-\") before accepting input","Pre-parse ranges with a regex like ^\\d*\\s*-\\s*\\d*$ before calling the API","Map this error to a user-facing 'invalid page range' message"],"exampleFix":"// before\nlet pages = parse_ranges(input, total)?;\n// after\nif !input.chars().all(|c| c.is_ascii_digit() || c == '-' || c == ',') {\n    anyhow::bail!(\"page range may contain only digits, '-' and ','\");\n}\nlet pages = parse_ranges(input, total)?;","handlingStrategy":"validation","validationCode":"fn valid_range_token(t: &str) -> bool {\n    let t = t.trim();\n    !t.is_empty() && t.chars().all(|c| c.is_ascii_digit() || c == '-') && t.matches('-').count() <= 1\n}","typeGuard":"fn is_page_spec(s: &str) -> bool { s.split(',').all(valid_range_token) }","tryCatchPattern":"let pages = parse_ranges(input, total).map_err(|e|\n    anyhow!(\"invalid page selection '{}': {}\", input, e))?;","preventionTips":["Validate the whole spec with a regex ^\\d*(-\\d*)?(,\\d*(-\\d*)?)*$ before calling","Trim and normalize user input (strip spaces/NBSP)","Show the accepted syntax in the UI placeholder","Never build range strings by raw string interpolation of untrusted values"],"tags":["pdf","parsing","validation","user-input"],"backgroundTag":"invalid-argument-format","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}