coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] split: --additional-suffix: disallow trailing '/'


From: Pádraig Brady
Subject: [PATCH] split: --additional-suffix: disallow trailing '/'
Date: Sun, 28 May 2023 15:21:58 +0100

Note mktemp --suffix has the same inconsistency,
but mktemp -d does support creating dirs
so probably best to leave that as is.

* src/split.c (main): Check for trailing /.
* tests/split/additional-suffix.sh: Augment the test.
Reported in https://bugs.debian.org/1036827
---
 src/split.c                      | 18 +++++++++++-------
 tests/split/additional-suffix.sh |  5 ++++-
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/src/split.c b/src/split.c
index 09209cc5a..436fa16df 100644
--- a/src/split.c
+++ b/src/split.c
@@ -1398,13 +1398,17 @@ main (int argc, char **argv)
           break;
 
         case ADDITIONAL_SUFFIX_OPTION:
-          if (last_component (optarg) != optarg)
-            {
-              error (0, 0,
-                     _("invalid suffix %s, contains directory separator"),
-                     quote (optarg));
-              usage (EXIT_FAILURE);
-            }
+          {
+            int suffix_len = strlen (optarg);
+            if (last_component (optarg) != optarg
+                || (suffix_len && ISSLASH (optarg[suffix_len - 1])))
+              {
+                error (0, 0,
+                       _("invalid suffix %s, contains directory separator"),
+                       quote (optarg));
+                usage (EXIT_FAILURE);
+              }
+          }
           additional_suffix = optarg;
           break;
 
diff --git a/tests/split/additional-suffix.sh b/tests/split/additional-suffix.sh
index ff9a9b546..9da8b35ea 100755
--- a/tests/split/additional-suffix.sh
+++ b/tests/split/additional-suffix.sh
@@ -39,6 +39,9 @@ compare exp-2 xab.txt || fail=1
 compare exp-3 xac.txt || fail=1
 
 # Additional suffix must not contain slash
-returns_ 1 split --lines=2 --additional-suffix=a/b in 2>/dev/null >out || 
fail=1
+returns_ 1 split --lines=2 --additional-suffix=a/b in 2>err >out || fail=1
+grep 'contains directory separator' err || fail=1
+returns_ 1 split --lines=2 --additional-suffix=a/ in 2>err >out || fail=1
+grep 'contains directory separator' err || fail=1
 
 Exit $fail
-- 
2.40.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]