git » spf » commit f462fb9

Ignore "exp" instead of returning Neutral

author Alberto Bertogli
2019-10-13 15:01:34 UTC
committer Alberto Bertogli
2019-10-14 12:18:21 UTC
parent b567bf74824a681b76976a6467129da7e0760b44

Ignore "exp" instead of returning Neutral

Currently, the library returns Neutral if the "exp" modifier is found
when processing a record, because it's not supported.

However, this is unnecessary, as we can simply ignore it. The modifier
is used for error reporting, so there's no downside of just continuing
through as if it didn't exist.

spf.go +3 -4
spf_test.go +1 -1

diff --git a/spf.go b/spf.go
index f4d45a1..bee90ba 100644
--- a/spf.go
+++ b/spf.go
@@ -16,10 +16,10 @@
 //   ip4
 //   ip6
 //   redirect
+//   exp (ignored)
 //
 // Not supported (return Neutral if used):
 //   exists
-//   exp
 //   Macros
 //
 // This is intentional and there are no plans to add them for now, as they are
@@ -93,7 +93,6 @@ var (
 	errLookupLimitReached = fmt.Errorf("lookup limit reached")
 	errMacrosNotSupported = fmt.Errorf("macros not supported")
 	errExistsNotSupported = fmt.Errorf("'exists' not supported")
-	errExpNotSupported    = fmt.Errorf("'exp' not supported")
 	errUnknownField       = fmt.Errorf("unknown field")
 	errInvalidIP          = fmt.Errorf("invalid ipX value")
 	errInvalidMask        = fmt.Errorf("invalid mask")
@@ -244,8 +243,8 @@ func (r *resolution) Check(domain string) (Result, error) {
 			trace("exists, neutral / not supported")
 			return Neutral, errExistsNotSupported
 		} else if strings.HasPrefix(field, "exp=") {
-			trace("exp=, neutral / not supported")
-			return Neutral, errExpNotSupported
+			trace("exp= not used, skipping")
+			continue
 		} else if strings.HasPrefix(field, "redirect=") {
 			trace("redirect, %q", field)
 			// https://tools.ietf.org/html/rfc7208#section-6.1
diff --git a/spf_test.go b/spf_test.go
index c5c482a..aa80a4b 100644
--- a/spf_test.go
+++ b/spf_test.go
@@ -26,6 +26,7 @@ func TestBasic(t *testing.T) {
 		{"v=spf1 ", Neutral, nil},
 		{"v=spf1 -", PermError, errUnknownField},
 		{"v=spf1 all", Pass, errMatchedAll},
+		{"v=spf1 exp=blah +all", Pass, errMatchedAll},
 		{"v=spf1  +all", Pass, errMatchedAll},
 		{"v=spf1 -all ", Fail, errMatchedAll},
 		{"v=spf1 ~all", SoftFail, errMatchedAll},
@@ -129,7 +130,6 @@ func TestNotSupported(t *testing.T) {
 		err error
 	}{
 		{"v=spf1 exists:blah -all", errExistsNotSupported},
-		{"v=spf1 exp=blah -all", errExpNotSupported},
 		{"v=spf1 a:%{o} -all", errMacrosNotSupported},
 		{"v=spf1 redirect=_spf.%{d}", errMacrosNotSupported},
 	}