Parse lines with quoted substrings right
This commit is contained in:
parent
2d65b370c8
commit
9adcdb14c4
|
@ -10,6 +10,8 @@ package bulb
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/yawning/bulb/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ProtocolInfo is the result of the ProtocolInfo command.
|
// ProtocolInfo is the result of the ProtocolInfo command.
|
||||||
|
@ -50,7 +52,7 @@ func (c *Conn) ProtocolInfo() (*ProtocolInfo, error) {
|
||||||
pi.RawResponse = resp
|
pi.RawResponse = resp
|
||||||
pi.AuthMethods = make(map[string]bool)
|
pi.AuthMethods = make(map[string]bool)
|
||||||
for i := 1; i < len(resp.Data); i++ {
|
for i := 1; i < len(resp.Data); i++ {
|
||||||
splitLine := strings.Split(resp.Data[i], " ")
|
splitLine := utils.SplitQuoted(resp.Data[i], '"', ' ')
|
||||||
switch splitLine[0] {
|
switch splitLine[0] {
|
||||||
case "AUTH":
|
case "AUTH":
|
||||||
// Parse an AuthLine detailing how to authenticate.
|
// Parse an AuthLine detailing how to authenticate.
|
||||||
|
|
|
@ -15,6 +15,24 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// SplitQuoted splits s by sep if it is found outside substring
|
||||||
|
// quoted by quote.
|
||||||
|
func SplitQuoted(s string, quote, sep rune) (splitted []string) {
|
||||||
|
quoteFlag := false
|
||||||
|
NewSubstring:
|
||||||
|
for i, c := range s {
|
||||||
|
if c == quote {
|
||||||
|
quoteFlag = !quoteFlag
|
||||||
|
}
|
||||||
|
if c == sep && !quoteFlag {
|
||||||
|
splitted = append(splitted, s[:i])
|
||||||
|
s = s[i+1:]
|
||||||
|
goto NewSubstring
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return append(splitted, s)
|
||||||
|
}
|
||||||
|
|
||||||
// ParseControlPortString parses a string representation of a control port
|
// ParseControlPortString parses a string representation of a control port
|
||||||
// address into a network/address string pair suitable for use with "dial".
|
// address into a network/address string pair suitable for use with "dial".
|
||||||
//
|
//
|
||||||
|
|
Reference in New Issue