Browse Source

Handle spaces in variables when not quoted

K. Lange 4 years ago
parent
commit
6430ce85b3
1 changed files with 13 additions and 2 deletions
  1. 13 2
      apps/sh.c

+ 13 - 2
apps/sh.c

@@ -647,8 +647,19 @@ int shell_exec(char * buffer, size_t size, FILE * file, char ** out_buffer) {
 						if (c) {
 							backtick = 0;
 							for (int i = 0; i < (int)strlen(c); ++i) {
-								buffer_[collected] = c[i];
-								collected++;
+								if (c[i] == ' ' && !quoted) {
+									/* If we are not quoted and we reach a space, it signals a new argument */
+									if (collected) {
+										buffer_[collected] = '\0';
+										add_argument(args, buffer_);
+										buffer_[0] = '\0';
+										have_star = 0;
+										collected = 0;
+									}
+								} else {
+									buffer_[collected] = c[i];
+									collected++;
+								}
 							}
 							buffer_[collected] = '\0';
 						}