fix(platform): use the platform's path separators

This commit is contained in:
Dylan M. Taylor
2026-11-03 11:53:33 +00:00
parent e239721816
commit 82fbdda588
2 changed files with 3 additions and 2 deletions
+1 -1
View File
@@ -44,7 +44,7 @@ fn create_staging_as(
keep: Option<&std::fs::Metadata>,
) -> std::io::Result<(PathBuf, std::fs::File)> {
// One name, in `dir`: a separator in it would put the staging file somewhere else.
if name.is_empty() || name.contains(['/', '\\']) {
if name.is_empty() || name.chars().any(std::path::is_separator) {
return Err(std::io::Error::new(std::io::ErrorKind::InvalidInput, "the file name is not a single name"));
}
// At most 128 bytes of the target's name, cut between characters, so the staging name fits
+2 -1
View File
@@ -464,7 +464,8 @@ fn a_replaced_link_keeps_its_own_attributes_not_its_targets() {
#[test]
fn a_name_with_path_components_is_refused() {
let dir = test_dir("components");
for name in ["../out.pdf", "sub/out.pdf", "sub\\out.pdf", "/out.pdf", ""] {
let windows_only: &[&str] = if cfg!(windows) { &["sub\\out.pdf"] } else { &[] };
for &name in ["../out.pdf", "sub/out.pdf", "/out.pdf", ""].iter().chain(windows_only) {
let err = create_staging(&dir, name, StagingName::SuffixThenTag, [0xab]).unwrap_err();
assert_eq!(err.kind(), std::io::ErrorKind::InvalidInput, "{name:?}");
}