Merge pull request #151 from Silvertree2010/fix/h5395-export-fails-to-write-files-whos

Fix export failing for file names with a max-length stem
This commit is contained in:
Brandon Thomas authored and GitHub committed 2026-11-02 19:24:52 -05:00
commit f07930ca8b
2 files changed
+15 -1

No files matched your search

+3 -1
View File
@@ -968,7 +968,9 @@ pub fn write_files(files: &[ExportedFile], dir: &std::path::Path) -> Result<Vec<
files
.iter()
.map(|f| {
if f.name.is_empty() || f.name != sanitize_file_stem(&f.name) || f.name.trim_matches('.').is_empty() {
// The planned name is `<sanitized stem>.<ext>`; the stem alone is capped at MAX_STEM.
let (stem, ext) = f.name.rsplit_once('.').unwrap_or((&f.name, ""));
if f.name.is_empty() || stem != sanitize_file_stem(stem) || !ext.chars().all(|c| c.is_ascii_alphanumeric()) || f.name.trim_matches('.').is_empty() {
return Err(FormatError::Invalid(format!("\"{}\" is not a plain file name", f.name)));
}
let path = dir.join(&f.name);
+12
View File
@@ -364,6 +364,18 @@ fn write_files_is_atomic_and_refuses_paths() {
std::fs::remove_dir_all(&dir).unwrap();
}
#[test]
fn write_files_accepts_planned_name_with_max_length_stem() {
let fx = Fx::new(&default_channels());
let files = fx.render_preset("Unreal Engine (Packed)");
let name = format!("{}.png", sanitize_file_stem(&"a".repeat(250)));
let dir = std::env::temp_dir().join(format!("tc-formats-export-long-{}", std::process::id()));
let long = ExportedFile { name, ..files[0].clone() };
let paths = write_files(&[long], &dir).unwrap();
assert_eq!(paths.len(), 1);
std::fs::remove_dir_all(&dir).unwrap();
}
fn gray_map(file: &str, src: SourceRef) -> MapSpec {
MapSpec { file: file.into(), format: FileFormat::Png, bit_depth: 8, channels: vec![(Dest::L, src)] }
}