Merge pull request #8791 from dekuu5/stat/fix-symlink-behavior
Some checks are pending
CICD / Style/cargo-deny (push) Waiting to run
CICD / Style/deps (push) Waiting to run
CICD / Documentation/warnings (push) Waiting to run
CICD / MinRustV (push) Waiting to run
CICD / Dependencies (push) Waiting to run
CICD / Build/Makefile (push) Blocked by required conditions
CICD / Build/stable (push) Blocked by required conditions
CICD / Build/nightly (push) Blocked by required conditions
CICD / Binary sizes (push) Blocked by required conditions
CICD / Build (push) Blocked by required conditions
CICD / Tests/BusyBox test suite (push) Blocked by required conditions
CICD / Tests/Toybox test suite (push) Blocked by required conditions
CICD / Code Coverage (push) Waiting to run
CICD / Separate Builds (push) Waiting to run
CICD / Test all features separately (push) Blocked by required conditions
CICD / Build/SELinux (push) Blocked by required conditions
CICD / Build/SELinux-Stubs (Non-Linux) (push) Blocked by required conditions
CICD / Safe Traversal Security Check (push) Blocked by required conditions
GnuTests / Run GNU tests (native) (push) Waiting to run
GnuTests / Run GNU tests (SELinux) (push) Waiting to run
GnuTests / Aggregate GNU test results (push) Blocked by required conditions
Android / Test builds (push) Waiting to run
Benchmarks / Run benchmarks (CodSpeed) (push) Waiting to run
Code Quality / Style/format (push) Waiting to run
Code Quality / Style/lint (push) Waiting to run
Code Quality / Style/spelling (push) Waiting to run
Code Quality / Style/toml (push) Waiting to run
Code Quality / Style/Python (push) Waiting to run
Code Quality / Pre-commit hooks (push) Waiting to run
Devcontainer / Verify devcontainer (push) Waiting to run
FreeBSD / Style and Lint (push) Waiting to run
FreeBSD / Tests (push) Waiting to run
WSL2 / Test (push) Waiting to run

stat: fix %N symlink to be single quote instead of double quote
This commit is contained in:
Ahmed hossam 2025-10-12 19:40:54 +03:00 committed by GitHub
parent f253efefaa
commit d79c18a693
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 27 additions and 2 deletions

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\'"
);
}
}

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]