Fix regex matching email in host search (#3539)

Fixes #3528
This commit is contained in:
Zach Wasserman
2021-12-31 09:16:25 -08:00
committed by GitHub
parent 404ca8a2bc
commit bda2ef0ca0
2 changed files with 23 additions and 2 deletions
+1 -1
View File
@@ -802,7 +802,7 @@ func searchLike(sql string, params []interface{}, match string, columns ...strin
// definitely not cut out any valid address is to just check for
// the presence of @, which is arguably the most important check
// in this.
var rxLooseEmail = regexp.MustCompile(`^[^\s@]+@[^\s@\.]\..+$`)
var rxLooseEmail = regexp.MustCompile(`^[^\s@]+@[^\s@\.]+\..+$`)
func hostSearchLike(sql string, params []interface{}, match string, columns ...string) (string, []interface{}) {
base, args := searchLike(sql, params, match, columns...)
+22 -1
View File
@@ -781,7 +781,7 @@ func TestNewUsesRegisterTLS(t *testing.T) {
require.Equal(t, "x509: certificate is not valid for any names, but wanted to match localhost", err.Error())
}
func TestWhereFilterTeas(t *testing.T) {
func TestWhereFilterTeams(t *testing.T) {
t.Parallel()
testCases := []struct {
@@ -939,3 +939,24 @@ func TestCompareVersions(t *testing.T) {
})
}
}
func TestRxLooseEmail(t *testing.T) {
testCases := []struct {
str string
match bool
}{
{"foo", false},
{"", false},
{"foo@example", false},
{"foo@example.com", true},
{"foo+bar@example.com", true},
{"foo.bar@example.com", true},
{"foo.bar@baz.example.com", true},
}
for _, tc := range testCases {
t.Run(tc.str, func(t *testing.T) {
assert.Equal(t, tc.match, rxLooseEmail.MatchString(tc.str))
})
}
}