mirror of
https://github.com/storytold/lightcraft.git
synced 2026-11-01 22:17:53 -06:00
Reject shutter fractions with a non-positive numerator or denominator
Found while testing crates/catalog/src/model.rs:160 (parse_shutter_seconds) 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:
co-authored by
Claude Haiku 5.5
parent
c4fd54e0a6
commit
7e92c28b23
@@ -157,7 +157,10 @@ impl CopyrightStatus {
|
||||
pub fn parse_shutter_seconds(s: &str) -> Option<f64> {
|
||||
let s = s.trim().trim_end_matches(['s', '"']).trim();
|
||||
match s.split_once('/') {
|
||||
Some((n, d)) => Some(n.trim().parse::<f64>().ok()? / d.trim().parse::<f64>().ok()?),
|
||||
Some((n, d)) => {
|
||||
let (n, d) = (n.trim().parse::<f64>().ok()?, d.trim().parse::<f64>().ok()?);
|
||||
if n > 0.0 && d > 0.0 { Some(n / d) } else { None }
|
||||
}
|
||||
None => s.parse().ok(),
|
||||
}
|
||||
.filter(|v: &f64| v.is_finite() && *v > 0.0)
|
||||
@@ -716,3 +719,16 @@ mod edited_tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod shutter_tests {
|
||||
use super::parse_shutter_seconds;
|
||||
|
||||
#[test]
|
||||
fn a_fraction_needs_a_positive_numerator_and_denominator() {
|
||||
for s in ["-1/-250", "1/-250", "-1/250", "0/250"] {
|
||||
assert_eq!(parse_shutter_seconds(s), None, "{s}");
|
||||
}
|
||||
assert_eq!(parse_shutter_seconds("1/250"), Some(0.004));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user