diff options
| author | Lucas Faria Mendes <lucas.fariamo08@gmail.com> | 2026-03-23 12:32:47 +0000 |
|---|---|---|
| committer | Lucas Faria Mendes <lucas.fariamo08@gmail.com> | 2026-03-23 12:32:47 +0000 |
| commit | 9dd509943776e72434b233a83c7d2ae02cb99455 (patch) | |
| tree | 3afb5880fea7db90aeb65df314ebc50d6d5c859d /src/parser.zig | |
| parent | fe6eba55e4daa6c7b3fd8b8eea10d2317e55ae7e (diff) | |
| download | shell-zig-9dd509943776e72434b233a83c7d2ae02cb99455.tar.gz shell-zig-9dd509943776e72434b233a83c7d2ae02cb99455.zip | |
fix again?
Diffstat (limited to 'src/parser.zig')
| -rw-r--r-- | src/parser.zig | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/parser.zig b/src/parser.zig index e0f28de..e04a4fb 100644 --- a/src/parser.zig +++ b/src/parser.zig @@ -20,13 +20,28 @@ pub fn parseCommand(input: []const u8) ParsedCommand { return .{ .name = "", .args = null, .output_redirect = null, .error_redirect = null, .append_output = null, .append_error = null }; } - if (input[i] == '\'' or input[i] == '"') { - const quote = input[i]; + if (input[i] == '\'') { i += 1; - while (i < input.len and input[i] != quote) : (i += 1) { + while (i < input.len and input[i] != '\'') : (i += 1) { _ = cmd_buf.append(std.heap.page_allocator, input[i]) catch {}; } if (i < input.len) i += 1; + } else if (input[i] == '"') { + i += 1; + while (i < input.len and input[i] != '"') : (i += 1) { + if (input[i] == '\\' and i + 1 < input.len) { + const next = input[i + 1]; + if (next == '"' or next == '\\') { + i += 1; + _ = cmd_buf.append(std.heap.page_allocator, input[i]) catch {}; + } else { + _ = cmd_buf.append(std.heap.page_allocator, input[i]) catch {}; + } + } else { + _ = cmd_buf.append(std.heap.page_allocator, input[i]) catch {}; + } + } + if (i < input.len) i += 1; } else { while (i < input.len and input[i] != ' ') : (i += 1) { if (input[i] == '\\' and i + 1 < input.len) { |