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

REFACTOR: Opinion: TXT records are one long string (#2631)

Co-authored-by: Costas Drogos <costas.drogos@gmail.com>
Co-authored-by: imlonghao <git@imlonghao.com>
Co-authored-by: Jeffrey Cafferata <jeffrey@jcid.nl>
Co-authored-by: Vincent Hagen <blackshadev@users.noreply.github.com>
This commit is contained in:
Tom Limoncelli
2023-12-04 17:45:25 -05:00
committed by GitHub
parent 88d26c3ea2
commit cbccbbeb8d
71 changed files with 882 additions and 747 deletions

View File

@@ -7,8 +7,12 @@ import (
"github.com/miekg/dns"
)
// IsQuoted returns true if the string starts and ends with a double quote.
func IsQuoted(s string) bool {
/*
TODO(tlim): Move this file to pkgs/txtutil. It doesn't need to be part
*/
// isQuoted returns true if the string starts and ends with a double quote.
func isQuoted(s string) bool {
if s == "" {
return false
}
@@ -24,7 +28,7 @@ func IsQuoted(s string) bool {
// StripQuotes returns the string with the starting and ending quotes removed.
// If it is not quoted, the original string is returned.
func StripQuotes(s string) string {
if IsQuoted(s) {
if isQuoted(s) {
return s[1 : len(s)-1]
}
return s
@@ -41,7 +45,7 @@ func StripQuotes(s string) string {
// NOTE: This doesn't handle escaped quotes.
// NOTE: You probably want to use ParseQuotedFields() for RFC 1035-compliant quoting.
func ParseQuotedTxt(s string) []string {
if !IsQuoted(s) {
if !isQuoted(s) {
return []string{s}
}
return strings.Split(StripQuotes(s), `" "`)