Skip to content
Snippets Groups Projects
Commit 485cafc2 authored by Apertis package maintainers's avatar Apertis package maintainers
Browse files

d/patches: refresh 'sort' fix with upstream version


Our previous patch was flawed in that it didn't allow for multiple `-k`
arguments. Upstream came up with a better solution so we should switch
to that one.

Signed-off-by: default avatarArnaud Ferraris <arnaud.ferraris@collabora.com>
parent ee7af9e6
No related branches found
No related tags found
1 merge request!6d/patches: refresh 'sort' fix with upstream version
From: Arnaud Ferraris <arnaud.ferraris@collabora.com>
Date: Fri, 11 Jun 2021 13:45:58 +0200
Subject: sort: fix `--key` argument handling
From: Michael Debertol <michael.debertol@gmail.com>
Date: Tue, Jul 6 13:26:28 2021 +0200
Subject: [PATCH] sort: make -k only take one argument per flag
When using `sort` with the `--key` option, all subsequent arguments
are considered its values, leading to failures such as:
$ sort -t ":" -k 3 /etc/passwd
sort: failed to parse key `/etc/passwd`: invalid option: `e`
This is a side-effect of having `multiple(true)` for this option,
as `multiple` supports separating values with either a comma or
whitespace. Therefore, as long as no other flag or option is
provided, all arguments following `-k` are treated like values
for this option.
Switching to `use_delimiter(true)` instead ensures only
comma-separated values are taken into account, and the following
arguments are properly interpreted.
Signed-off-by: Arnaud Ferraris <arnaud.ferraris@collabora.com>
Forwarded: https://github.com/uutils/coreutils/pull/2403
This makes it so that `sort -k 1 file` treats `file` as the input file
and not the second key.
---
src/uu/sort/src/sort.rs | 1 -
1 file changed, 1 deletion(-)
src/uu/sort/src/sort.rs | 1 +
tests/by-util/test_sort.rs | 8 +
2 files changed, 9 insertion(+), 0 deletion(-)
diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs
index 7b1fe07..c4d9e60 100644
index 1ba5ee0b..55bcdb77 100644
--- a/src/uu/sort/src/sort.rs
+++ b/src/uu/sort/src/sort.rs
@@ -658,7 +658,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
.long(OPT_KEY)
@@ -659,6 +659,7 @@ pub fn uu_app() -> App<'static, 'static> {
.help("sort by a key")
.long_help(LONG_HELP_KEYS)
- .multiple(true)
+ .use_delimiter(true)
.multiple(true)
+ .number_of_values(1)
.takes_value(true),
)
.arg(
diff --git a/tests/by-util/test_sort.rs b/tests/by-util/test_sort.rs
index 1d41ddac..4a1cc3fa 100644
--- a/tests/by-util/test_sort.rs
+++ b/tests/by-util/test_sort.rs
@@ -556,3 +556,11 @@ fn test_check_silent() {
.fails()
.stdout_is("");
}
+
+#[test]
+fn test_key_takes_one_arg() {
+ new_ucmd!()
+ .args(&["-k", "2.3", "keys_open_ended.txt"])
+ .succeeds()
+ .stdout_is_fixture("keys_open_ended.expected");
+}
--
2.30.2
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment