mirror of
https://github.com/storytold/cadcraft.git
synced 2026-12-02 02:38:30 -06:00
27 lines
1.1 KiB
Rust
27 lines
1.1 KiB
Rust
//! A drawing path that isn't valid Unicode is refused: the session keeps paths as text, so it
|
|
//! could never be saved back to.
|
|
|
|
#![cfg(unix)]
|
|
|
|
use std::ffi::OsString;
|
|
use std::os::unix::ffi::OsStringExt;
|
|
|
|
use cadcraft_doc::Drawing;
|
|
use cadcraft_engine::cmd::file::{IoHooks, read_file, set_io};
|
|
|
|
#[test]
|
|
fn read_file_refuses_a_name_that_is_not_unicode() {
|
|
set_io(IoHooks { read: |_, _| Ok(Drawing::new_metric()), write: |_, _| Ok(Vec::new()), plot: None });
|
|
let dir = std::env::temp_dir().join(format!("cadcraft-nonunicode-{}", std::process::id()));
|
|
std::fs::create_dir_all(&dir).unwrap();
|
|
let good = dir.join("good.dxf");
|
|
let bad = dir.join(OsString::from_vec(b"bad-\xff.dxf".to_vec()));
|
|
std::fs::write(&good, b"0\nEOF\n").unwrap();
|
|
// Validation precedes filesystem access; macOS filesystems may reject this name.
|
|
assert!(!bad.exists());
|
|
let e = read_file(&bad).err().expect("a non-Unicode name is refused");
|
|
assert!(e.contains("not valid Unicode") && e.contains("bad-"), "{e}");
|
|
assert!(read_file(&good).is_ok());
|
|
let _ = std::fs::remove_dir_all(&dir);
|
|
}
|