Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ls: fix for gnu test case quote-align compatibility #6555

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/uu/ls/src/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2037,12 +2037,18 @@ impl PathData {
}

fn show_dir_name(path_data: &PathData, out: &mut BufWriter<Stdout>, config: &Config) {
let name = escape_name(
path_data.p_buf.as_os_str(),
&config.quoting_style,
// We tell `escape_name` to quote if it contains ':' because the user
// could distinguish it from the ":" we are about to print next.
&[':'],
);
if config.hyperlink && !config.dired {
let name = escape_name(path_data.p_buf.as_os_str(), &config.quoting_style);
let hyperlink = create_hyperlink(&name, path_data);
write!(out, "{}:", hyperlink).unwrap();
} else {
write!(out, "{}:", path_data.p_buf.display()).unwrap();
write!(out, "{}:", name).unwrap();
}
}

Expand Down Expand Up @@ -2499,7 +2505,7 @@ fn display_items(
// option, print the security context to the left of the size column.

let quoted = items.iter().any(|item| {
let name = escape_name(&item.display_name, &config.quoting_style);
let name = escape_name(&item.display_name, &config.quoting_style, &[]);
name.starts_with('\'')
});

Expand Down Expand Up @@ -3213,7 +3219,7 @@ fn display_item_name(
current_column: usize,
) -> String {
// This is our return value. We start by `&path.display_name` and modify it along the way.
let mut name = escape_name(&path.display_name, &config.quoting_style);
let mut name = escape_name(&path.display_name, &config.quoting_style, &[]);

let is_wrap =
|namelen: usize| config.width != 0 && current_column + namelen > config.width.into();
Expand Down Expand Up @@ -3295,7 +3301,7 @@ fn display_item_name(
name.push_str(&path.p_buf.read_link().unwrap().to_string_lossy());
} else {
name.push_str(&color_name(
&escape_name(target.as_os_str(), &config.quoting_style),
&escape_name(target.as_os_str(), &config.quoting_style, &[]),
path,
style_manager,
out,
Expand All @@ -3306,7 +3312,7 @@ fn display_item_name(
} else {
// If no coloring is required, we just use target as is.
// Apply the right quoting
name.push_str(&escape_name(target.as_os_str(), &config.quoting_style));
name.push_str(&escape_name(target.as_os_str(), &config.quoting_style, &[]));
}
}
Err(err) => {
Expand Down
10 changes: 5 additions & 5 deletions src/uu/wc/src/wc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@
match self {
Self::Path(path) => Some(match path.to_str() {
Some(s) if !s.contains('\n') => Cow::Borrowed(s),
_ => Cow::Owned(escape_name(path.as_os_str(), QS_ESCAPE)),
_ => Cow::Owned(escape_name(path.as_os_str(), QS_ESCAPE, &[])),
}),
Self::Stdin(StdinKind::Explicit) => Some(Cow::Borrowed(STDIN_REPR)),
Self::Stdin(StdinKind::Implicit) => None,
Expand All @@ -269,7 +269,7 @@
/// Converts input into the form that appears in errors.
fn path_display(&self) -> String {
match self {
Self::Path(path) => escape_name(path.as_os_str(), QS_ESCAPE),
Self::Path(path) => escape_name(path.as_os_str(), QS_ESCAPE, &[]),
Self::Stdin(_) => String::from("standard input"),
}
}
Expand Down Expand Up @@ -361,7 +361,7 @@
Some((input, idx)) => {
let path = match input {
Input::Stdin(_) => STDIN_REPR.into(),
Input::Path(path) => escape_name(path.as_os_str(), QS_ESCAPE).into(),
Input::Path(path) => escape_name(path.as_os_str(), QS_ESCAPE, &[]).into(),
};
Self::ZeroLengthFileNameCtx { path, idx }
}
Expand Down Expand Up @@ -761,7 +761,7 @@
Err(e) => Err(e.map_err_context(|| {
format!(
"cannot open {} for reading",
escape_name(path.as_os_str(), QS_QUOTE_ESCAPE)
escape_name(path.as_os_str(), QS_QUOTE_ESCAPE, &[])

Check warning on line 764 in src/uu/wc/src/wc.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/wc/src/wc.rs#L764

Added line #L764 was not covered by tests
)
})),
}
Expand Down Expand Up @@ -794,7 +794,7 @@
}
}
Err(e) => Err(e.map_err_context(|| {
format!("{}: read error", escape_name(&err_path, QS_ESCAPE))
format!("{}: read error", escape_name(&err_path, QS_ESCAPE, &[]))
}) as Box<dyn UError>),
}),
);
Expand Down
1 change: 1 addition & 0 deletions src/uucore/src/lib/features/format/argument.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ fn extract_value<T: Default>(p: Result<T, ParseError<'_, T>>, input: &str) -> T
&QuotingStyle::C {
quotes: Quotes::None,
},
&[],
);
match e {
ParseError::Overflow => {
Expand Down
1 change: 1 addition & 0 deletions src/uucore/src/lib/features/format/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ impl Spec {
always_quote: false,
show_control: false,
},
&[],
)
.as_bytes(),
)
Expand Down
Loading
Loading