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 1/2] hush: Fix handling '\ '
Date: Thu, 27 Oct 2022 10:47:44 +0200	[thread overview]
Message-ID: <20221027084745.395052-1-s.hauer@pengutronix.de> (raw)

Currently when doing:

echo foo\ bar

we will get argv[1] = "foo\" and argv[2] = "bar".

An unquoted escaped whitespace should be replaced by a whitespace.
With this the above will correctly result in argv[1] = "foo bar"

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/hush.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/common/hush.c b/common/hush.c
index 6a089fabf1..5138a1a45a 100644
--- a/common/hush.c
+++ b/common/hush.c
@@ -617,6 +617,7 @@ static int builtin_exit(struct p_context *ctx, struct child_prog *child,
 static void remove_quotes_in_str(char *src)
 {
 	char *trg = src;
+	bool in_double_quotes = false;
 
 	while (*src) {
 		if (*src == '\'') {
@@ -629,6 +630,7 @@ static void remove_quotes_in_str(char *src)
 
 		/* drop quotes */
 		if (*src == '"') {
+			in_double_quotes = !in_double_quotes;
 			src++;
 			continue;
 		}
@@ -654,6 +656,13 @@ static void remove_quotes_in_str(char *src)
 			continue;
 		}
 
+		/* replace '\ ' with ' ' */
+		if (!in_double_quotes && *src == '\\' && *(src + 1) == ' ') {
+			*trg++ = ' ';
+			src += 2;
+			continue;
+		}
+
 		*trg++ = *src++;
 	}
 	*trg = 0;
-- 
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 Sascha Hauer [this message]
2022-10-27  8:47 ` [PATCH 2/2] readline: Complete strings containing whitespaces correctly Sascha Hauer

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-1-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