[PATCH 2/2] readline: Complete strings containing whitespaces correctly

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

 



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@xxxxxxxxxxxxxx>
---
 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





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux