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 { func parseCommand(line string) []string {
var parts []string var parts []string
var current strings.Builder var current strings.Builder
var quoteChar byte // Track which quote char started this argument (' or ")
inQuotes := false inQuotes := false
for i := 0; i < len(line); i++ { for i := 0; i < len(line); i++ {
ch := line[i] ch := line[i]
switch ch {
case '"': // Check if this is a quote character at the start of a new argument
inQuotes = !inQuotes if (ch == '"' || ch == '\'') && current.Len() == 0 && !inQuotes {
case ' ', '\t': // Starting a quoted argument - remember the quote type
if inQuotes { quoteChar = ch
current.WriteByte(ch) inQuotes = true
} else if current.Len() > 0 { 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()) parts = append(parts, current.String())
current.Reset() current.Reset()
} }
default: continue
current.WriteByte(ch)
} }
// Add all other characters (including quotes inside unquoted args)
current.WriteByte(ch)
} }
if current.Len() > 0 { if current.Len() > 0 {