[Toybox] [PATCH] ls: Ensure file names are separated by 2 spaces

Andrew Ilijic ilijic.andrew at gmail.com
Thu Oct 17 08:30:29 PDT 2019


>From d4c03b672d8b18f7ce021e4fcb02e8bb86f38f5f Mon Sep 17 00:00:00 2001
From: Andrew Ilijic <ilijic.andrew at gmail.com>
Date: Thu, 17 Oct 2019 11:03:19 -0400
Subject: [PATCH] ls: Ensure file names are separated by 2 spaces

We need two spaces between filenames because that is the convention
followed by other implementations. More importantly, if we do not have
two spaces, certain Unicode file names cause filenames to run together.
In Unicode, combining characters come before the character they modify.
If a filename ends in a combining character, the combining character
attaches to the space that follows it, causing the space not to be
visible. Having a two-space gap stops the above issue from happening.

For context and a bit more information, see mailing list link below.
https://www.mail-archive.com/toybox@lists.landley.net/msg05986.html
---
 toys/posix/ls.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/toys/posix/ls.c b/toys/posix/ls.c
index 0956902f..d4c0211a 100644
--- a/toys/posix/ls.c
+++ b/toys/posix/ls.c
@@ -384,7 +384,8 @@ static void listfiles(int dirfd, struct dirtree *indir)
       memset(colsizes, 0, columns*sizeof(unsigned));
       for (ul=0; ul<dtlen; ul++) {
         entrylen(sort[next_column(ul, dtlen, columns, &c)], len);
-        *len += totpad+1;
+        // Add `2` to `totpad` to ensure two spaces between filenames
+        *len += totpad+2;
         if (c == columns) break;
         // Expand this column if necessary, break if that puts us over budget
         if (*len > colsizes[c]) {
-- 
2.11.0
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-ls-Ensure-file-names-are-separated-by-2-spaces.patch
Type: text/x-patch
Size: 1566 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20191017/12085810/attachment-0002.bin>


More information about the Toybox mailing list