Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing of matching structure from array to map for golang #296

Merged
merged 1 commit into from
Jan 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions platform/go/mail_checker.go

Large diffs are not rendered by default.

22 changes: 16 additions & 6 deletions platform/go/mail_checker.tmpl._go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,23 @@ var (
// emailRegex from https://github.com/asaskevich/govalidator as the go regex implementation does not fully support Perl
// syntax: (?!
emailRegex = regexp.MustCompile("^(((([a-zA-Z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])+(\\.([a-zA-Z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])+)*)|((\\x22)((((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(([\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]|\\x21|[\\x23-\\x5b]|[\\x5d-\\x7e]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(\\([\\x01-\\x09\\x0b\\x0c\\x0d-\\x7f]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}]))))*(((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(\\x22)))@((([a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(([a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])([a-zA-Z]|\\d|-|\\.|_|~|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])*([a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])))\\.)+(([a-zA-Z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(([a-zA-Z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])([a-zA-Z]|\\d|-|_|~|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])*([a-zA-Z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])))\\.?$")
blacklist = []string{
blacklist = newMap([]string{
{{&listSTR}},
}
})
itemExists = struct{}{}
)

func newMap(domains []string) map[string]struct{} {

m := make(map[string]struct{}, len(domains))

for _, domain := range domains {
m[domain] = itemExists
}

return m
}

func allDomainSuffixes(domain string) []string {

components := strings.Split(domain, ".")
Expand Down Expand Up @@ -45,10 +57,8 @@ func IsBlacklisted(email string) bool {
}

for _, domainSuffix := range allDomainSuffixes(parts[1]) {
for _, blacklistedDomain := range blacklist {
if blacklistedDomain == domainSuffix {
return true
}
if _, contains := blacklist[domainSuffix]; contains {
return true
}
}

Expand Down
2 changes: 1 addition & 1 deletion platform/go/mail_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestReturnFalseForBlacklistedDomainsAndTheirSubdomains(t *testing.T) {
}

for i, testCase := range testCases {
for _, blacklistedDomain := range blacklist {
for blacklistedDomain := range blacklist {

email := fmt.Sprintf(testCase.template, blacklistedDomain)
result := IsValid(email)
Expand Down