diff --git a/src/uu/mktemp/src/mktemp.rs b/src/uu/mktemp/src/mktemp.rs index 4a77da4c4..6a3f6f21b 100644 --- a/src/uu/mktemp/src/mktemp.rs +++ b/src/uu/mktemp/src/mktemp.rs @@ -281,7 +281,7 @@ impl Params { .join(prefix_from_template) .display() .to_string(); - if options.treat_as_template && prefix.contains(MAIN_SEPARATOR) { + if options.treat_as_template && prefix_from_template.contains(MAIN_SEPARATOR) { return Err(MkTempError::PrefixContainsDirSeparator(options.template)); } if tmpdir.is_some() && Path::new(prefix_from_template).is_absolute() { diff --git a/tests/by-util/test_mktemp.rs b/tests/by-util/test_mktemp.rs index f99f92a80..907f8cf1d 100644 --- a/tests/by-util/test_mktemp.rs +++ b/tests/by-util/test_mktemp.rs @@ -23,6 +23,7 @@ static TEST_TEMPLATE7: &str = "XXXtemplate"; // spell-checker:disable-line static TEST_TEMPLATE8: &str = "tempXXXl/ate"; #[cfg(windows)] static TEST_TEMPLATE8: &str = "tempXXXl\\ate"; +static TEST_TEMPLATE9: &str = "a.XXXX"; #[cfg(not(windows))] const TMPDIR: &str = "TMPDIR"; @@ -569,6 +570,34 @@ fn test_template_path_separator() { )); } +/// Test that a prefix with a point is valid. +#[test] +fn test_prefix_template_separator() { + new_ucmd!() + .args(&["-p", ".", "-t", TEST_TEMPLATE9]) + .succeeds(); +} + +#[test] +fn test_prefix_template_with_path_separator() { + #[cfg(not(windows))] + new_ucmd!() + .args(&["-t", "a/XXX"]) + .fails() + .stderr_only(format!( + "mktemp: invalid template, {}, contains directory separator\n", + "a/XXX".quote() + )); + #[cfg(windows)] + new_ucmd!() + .args(&["-t", r"a\XXX"]) + .fails() + .stderr_only(format!( + "mktemp: invalid template, {}, contains directory separator\n", + r"a\XXX".quote() + )); +} + /// Test that a suffix with a path separator is invalid. #[test] fn test_suffix_path_separator() {