1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Merge pull request #4379 from ZauJulio/hotfix-mktemp

mktemp: fix PrefixContainsDirSeparator verification
This commit is contained in:
Sylvestre Ledru 2023-04-26 18:28:56 +02:00 committed by GitHub
commit 0f268428fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 1 deletions

View file

@ -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() {

View file

@ -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() {