mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Cc: afa@pengutronix.de
Subject: [PATCH 2/2] readline: Complete strings containing whitespaces correctly
Date: Thu, 27 Oct 2022 10:47:45 +0200	[thread overview]
Message-ID: <20221027084745.395052-2-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20221027084745.395052-1-s.hauer@pengutronix.de>

Completion strings containing whitespaces have to end up as a single
argv[] argument, thus the whitespaces have to be escaped. Fix this.

Ideally the whitespaces should only be escaped when we are outside of
double or single quotes, but our completion currently doesn't trigger
at all when invokes inside quotes, so we can ignore this case for now.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 lib/readline.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lib/readline.c b/lib/readline.c
index 37d5b0a343..92bec3d1d8 100644
--- a/lib/readline.c
+++ b/lib/readline.c
@@ -230,9 +230,14 @@ int readline(const char *prompt, char *buf, int len)
 			}
 
 			i = 0;
-			while (completestr[i])
+			while (completestr[i]) {
+				if (completestr[i] == ' ' && completestr[i + 1])
+					cread_add_char('\\', insert, &num,
+						&eol_num, buf, len);
+
 				cread_add_char(completestr[i++], insert, &num,
 						&eol_num, buf, len);
+			}
 #endif
 			break;
 
-- 
2.30.2




      reply	other threads:[~2022-10-27  8:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-27  8:47 [PATCH 1/2] hush: Fix handling '\ ' Sascha Hauer
2022-10-27  8:47 ` Sascha Hauer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221027084745.395052-2-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=afa@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox