mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Fix generator spaced size keeping size text in asset file name (#6628)
Found while testing crates/engine/src/web_cmds.rs:1171 Co-authored-by: Claude Haiku 5.5 <[email protected]>
This commit is contained in:
1 parent
e8ab6846c0
commit
fb5896f43f
2 files changed
+20
-2
No files matched your search
@@ -1189,8 +1189,12 @@ fn parse_size(item: &str, dpi: f64) -> (Option<f64>, Option<f64>, Option<f64>, &
|
||||
&& toks[1].eq_ignore_ascii_case("x")
|
||||
&& let (Some(w), Some(h)) = (unit_px(toks[0], dpi), unit_px(toks[2], dpi))
|
||||
{
|
||||
let pos = item.find(toks[3]).unwrap_or(item.len());
|
||||
return (None, w, h, &item[pos..]);
|
||||
// Skip exactly the three size tokens; searching for the name's first word could match inside the size.
|
||||
let mut rest = item;
|
||||
for _ in 0..3 {
|
||||
rest = rest.trim_start().trim_start_matches(|c: char| !c.is_whitespace());
|
||||
}
|
||||
return (None, w, h, rest.trim_start());
|
||||
}
|
||||
(None, None, None, item)
|
||||
}
|
||||
|
||||
@@ -533,6 +533,20 @@ fn webp_export_preferences_select_lossless_or_lossy_output() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn generator_spaced_size_keeps_only_the_file_name() {
|
||||
for (name, w, h, file) in [
|
||||
("2 x 2 2 icon.png", 2.0, 2.0, "2 icon.png"),
|
||||
("1in x 1in in.png", 72.0, 72.0, "in.png"),
|
||||
("2px x 1px x.png", 2.0, 1.0, "x.png"),
|
||||
("2in x 1in label name.png", 144.0, 72.0, "label name.png"),
|
||||
] {
|
||||
let a = parse_asset_name(name, 72.0);
|
||||
assert_eq!(a.len(), 1, "{name}");
|
||||
assert_eq!((a[0].width, a[0].height, a[0].file.as_str()), (Some(w), Some(h), file), "{name}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn generator_naming_grammar() {
|
||||
let a = parse_asset_name("200% [email protected], 48x48 icons/bar.png8 + photo.jpg8", 72.0);
|
||||
|
||||
Reference in new issue
Block a user