mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-16 10:55:47 +00:00
fix(platform): use the platform's path separators
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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:?}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user