git » spf » commit bb04820

Enforce fields are space-separated

author Alberto Bertogli
2019-10-14 01:37:42 UTC
committer Alberto Bertogli
2019-10-14 12:35:29 UTC
parent 00961f6d3085d2d7fec47c73c9b02418b618cd2e

Enforce fields are space-separated

The standard is clear the only valid separator is " ", so use it to
split the fields.

Found by the standard test suite.

spf.go +5 -1

diff --git a/spf.go b/spf.go
index 1824128..45139ea 100644
--- a/spf.go
+++ b/spf.go
@@ -178,7 +178,7 @@ func (r *resolution) Check(domain string) (Result, error) {
 		return None, nil
 	}
 
-	fields := strings.Fields(txt)
+	fields := strings.Split(txt, " ")
 
 	// redirects must be handled after the rest; instead of having two loops,
 	// we just move them to the end.
@@ -193,6 +193,10 @@ func (r *resolution) Check(domain string) (Result, error) {
 	fields = append(newfields, redirects...)
 
 	for _, field := range fields {
+		if field == "" {
+			continue
+		}
+
 		// The version check should be case-insensitive (it's a
 		// case-insensitive constant in the standard).
 		// https://tools.ietf.org/html/rfc7208#section-12