mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-20 22:40:44 +01:00
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:
2 files changed
+15
-1
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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)] }
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user