From c085185296a2954d7a9c3afebfaf9ee271ac40c1 Mon Sep 17 00:00:00 2001 From: NetterSilver <133535268+Silvertree2010@users.noreply.github.com> Date: Sat, 7 Nov 2026 21:51:38 +0100 Subject: [PATCH 1/2] Ignore non-digit suffixes in next_asset_name Found while testing crates/doc/src/assets.rs:43 (Document::next_asset_name) Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Sonnet 5.5 --- crates/doc/src/assets.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/crates/doc/src/assets.rs b/crates/doc/src/assets.rs index 824f3ebea..b75a5873b 100644 --- a/crates/doc/src/assets.rs +++ b/crates/doc/src/assets.rs @@ -34,7 +34,16 @@ impl Document { /// The name of the next unnamed asset: one more than the highest `Asset N` so far. pub fn next_asset_name(&self) -> String { - let n = self.assets.iter().filter_map(|a| a.name.strip_prefix(ASSET)?.parse::().ok()).max().unwrap_or(0); + let n = self + .assets + .iter() + .filter_map(|a| { + let digits = a.name.strip_prefix(ASSET)?; + // `parse` alone would accept a leading `+`. + digits.bytes().all(|b| b.is_ascii_digit()).then(|| digits.parse::().ok()).flatten() + }) + .max() + .unwrap_or(0); format!("{ASSET}{}", n.saturating_add(1)) } @@ -61,3 +70,23 @@ impl Document { v.into_iter().map(|(_, id)| id).collect() } } + +#[cfg(test)] +mod tests { + use super::*; + + fn name_after(names: &[&str]) -> String { + let mut doc = Document::new(100.0, 100.0); + for (i, n) in names.iter().enumerate() { + doc.assets.push(ExportAsset { id: i as u64 + 1, name: (*n).to_string(), nodes: vec![] }); + } + doc.next_asset_name() + } + + #[test] + fn next_asset_name_ignores_non_digit_suffixes() { + assert_eq!(name_after(&["Asset +5"]), "Asset 1"); + assert_eq!(name_after(&["Asset ", "Asset 5x"]), "Asset 1"); + assert_eq!(name_after(&["Asset 5"]), "Asset 6"); + } +} From 8199f30c747bec12f518d94bf44dc0a88743ce0b Mon Sep 17 00:00:00 2001 From: bflatastic Date: Mon, 9 Nov 2026 01:38:42 +0700 Subject: [PATCH 2/2] Export for Screens: the asset-name test sets main's 3D format field --- crates/doc/src/assets.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/doc/src/assets.rs b/crates/doc/src/assets.rs index b75a5873b..f17783b1e 100644 --- a/crates/doc/src/assets.rs +++ b/crates/doc/src/assets.rs @@ -78,7 +78,7 @@ mod tests { fn name_after(names: &[&str]) -> String { let mut doc = Document::new(100.0, 100.0); for (i, n) in names.iter().enumerate() { - doc.assets.push(ExportAsset { id: i as u64 + 1, name: (*n).to_string(), nodes: vec![] }); + doc.assets.push(ExportAsset { id: i as u64 + 1, name: (*n).to_string(), nodes: vec![], format_3d: None }); } doc.next_asset_name() }