Merge pull request #8791 from dekuu5/stat/fix-symlink-behavior

stat: fix %N symlink to be single quote instead of double quote
This commit is contained in:
Ahmed hossam
2025-10-12 18:40:54 +02:00
committed by GitHub
parent f253efefaa
commit d79c18a693
2 changed files with 27 additions and 2 deletions
+20 -2
View File
@@ -439,7 +439,10 @@ fn quote_file_name(file_name: &str, quoting_style: &QuotingStyle) -> String {
let escaped = file_name.replace('\'', r"\'");
format!("'{escaped}'")
}
QuotingStyle::ShellEscapeAlways => format!("\"{file_name}\""),
QuotingStyle::ShellEscapeAlways => {
let quote = if file_name.contains('\'') { '"' } else { '\'' };
format!("{quote}{file_name}{quote}")
}
QuotingStyle::Quote => file_name.to_string(),
}
}
@@ -1378,7 +1381,7 @@ fn pretty_time(meta: &Metadata, md_time_field: MetadataTimeField) -> String {
#[cfg(test)]
mod tests {
use crate::{pad_and_print_bytes, print_padding};
use crate::{pad_and_print_bytes, print_padding, quote_file_name};
use super::{Flags, Precision, ScanUtil, Stater, Token, group_num, precision_trunc};
@@ -1529,4 +1532,19 @@ mod tests {
print_padding(&mut buffer, 5).unwrap();
assert_eq!(&buffer, b" ");
}
#[test]
fn test_quote_file_name() {
let file_name = "nice' file";
assert_eq!(
quote_file_name(file_name, &crate::QuotingStyle::ShellEscapeAlways),
"\"nice' file\""
);
let file_name = "nice\" file";
assert_eq!(
quote_file_name(file_name, &crate::QuotingStyle::ShellEscapeAlways),
"\'nice\" file\'"
);
}
}
+7
View File
@@ -435,6 +435,13 @@ fn test_quoting_style_locale() {
.args(&["-c", "%N", "'"])
.succeeds()
.stdout_only("\"'\"\n");
// testing file having "
at.touch("\"");
ts.ucmd()
.args(&["-c", "%N", "\""])
.succeeds()
.stdout_only("\'\"\'\n");
}
#[test]