mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-30 20:58:00 -06:00
Reject a sign after # in EPS PostScript radix numbers
Found while testing crates/eps/src/import/lex.rs:287-289 (number) Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
committed by
bflatastic
co-authored by
Claude Haiku 5.5
parent
aca98ffe79
commit
ddd017eb0a
@@ -286,6 +286,10 @@ fn number(w: &str) -> Option<Obj> {
|
||||
}
|
||||
if let Some((base, digits)) = w.split_once('#') {
|
||||
let base: u32 = base.parse().ok().filter(|b| (2..=36).contains(b))?;
|
||||
// `from_str_radix` accepts a leading sign; a PostScript radix number has digits only.
|
||||
if digits.starts_with(['+', '-']) {
|
||||
return None;
|
||||
}
|
||||
return i64::from_str_radix(digits, base).ok().map(Obj::Int);
|
||||
}
|
||||
// Rust reads `inf` and `nan`; PostScript doesn't.
|
||||
@@ -295,3 +299,15 @@ fn number(w: &str) -> Option<Obj> {
|
||||
let v: f64 = w.parse().ok()?;
|
||||
v.is_finite().then_some(Obj::Real(v))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn radix_number_with_sign_after_hash_is_not_a_number() {
|
||||
assert!(number("16#+ff").is_none());
|
||||
assert!(number("16#-ff").is_none());
|
||||
assert!(matches!(number("16#ff"), Some(Obj::Int(255))));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user