From a4227d25c7432ec8b30ff0c16862c7dd5a0c2bc4 Mon Sep 17 00:00:00 2001 From: ryyst Date: Sun, 5 Oct 2025 22:23:31 +0300 Subject: [PATCH] fix: JSON quote parsing --- main.go | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index 6da0847..77381da 100644 --- a/main.go +++ b/main.go @@ -561,23 +561,39 @@ var completer = readline.NewPrefixCompleter( func parseCommand(line string) []string { var parts []string var current strings.Builder + var quoteChar byte // Track which quote char started this argument (' or ") inQuotes := false for i := 0; i < len(line); i++ { ch := line[i] - switch ch { - case '"': - inQuotes = !inQuotes - case ' ', '\t': - if inQuotes { - current.WriteByte(ch) - } else if current.Len() > 0 { + + // Check if this is a quote character at the start of a new argument + if (ch == '"' || ch == '\'') && current.Len() == 0 && !inQuotes { + // Starting a quoted argument - remember the quote type + quoteChar = ch + inQuotes = true + continue // Don't add the quote itself + } + + // Check if this is the closing quote + if inQuotes && ch == quoteChar { + // End quoted argument + inQuotes = false + quoteChar = 0 + continue // Don't add the quote itself + } + + // Handle spaces/tabs + if (ch == ' ' || ch == '\t') && !inQuotes { + if current.Len() > 0 { parts = append(parts, current.String()) current.Reset() } - default: - current.WriteByte(ch) + continue } + + // Add all other characters (including quotes inside unquoted args) + current.WriteByte(ch) } if current.Len() > 0 {