fix: JSON quote parsing

This commit is contained in:
2025-10-05 22:23:31 +03:00
parent 6cfd5d5c31
commit a4227d25c7

34
main.go
View File

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