1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

BUGFIX: CAA records may include quoted spaces #1374 (#1377)

This commit is contained in:
Tom Limoncelli
2022-01-25 09:57:20 -05:00
committed by GitHub
parent 263c6b7290
commit b73d37908c
4 changed files with 49 additions and 4 deletions

View File

@@ -1,6 +1,9 @@
package models
import "strings"
import (
"encoding/csv"
"strings"
)
// IsQuoted returns true if the string starts and ends with a double quote.
func IsQuoted(s string) bool {
@@ -35,3 +38,14 @@ func ParseQuotedTxt(s string) []string {
}
return strings.Split(StripQuotes(s), `" "`)
}
// ParseQuotedFields is like strings.Fields except individual fields
// might be quoted using `"`.
func ParseQuotedFields(s string) ([]string, error) {
// Fields are space-separated but a field might be quoted. This is,
// essentially, a CSV where spaces are the field separator (not
// commas). Therefore, we use the CSV parser. See https://stackoverflow.com/a/47489846/71978
r := csv.NewReader(strings.NewReader(s))
r.Comma = ' ' // space
return r.Read()
}