mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-29 12:17:14 -06:00
Merge pull request #4460 from Silvertree2010/fix/h3582-eps-import-postscript-radix-numb
Reject a sign after # in EPS PostScript radix numbers
This commit is contained in:
@@ -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