From f9c6ab6e8ae40016c8e221a41d3d9704424d8a9f Mon Sep 17 00:00:00 2001 From: Ryan McDonald Date: Tue, 28 Apr 2015 09:17:36 -0600 Subject: [PATCH 1/5] QRA-784: Accept utf8 characters for local and domain --- nibbler.go | 5 ++--- nibbler_test.go | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nibbler.go b/nibbler.go index 4ea2ae5..6a4f4ce 100644 --- a/nibbler.go +++ b/nibbler.go @@ -11,9 +11,9 @@ type state struct { const () const ( - ATEXT = "!#$%&'*+-/=?^_`.{|}~@\"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" + ATEXT = "!#$%&'*+-/=?^_`.{|}~@\"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞSSÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ÷ØÙÚÛÜÝÞŸàáâãäåæçèéêëìíîïðñòóôõö×øùúûüýþssàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ" SPECIAL = "(),:;<>[\\] " - HOSTNAME = "-.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" + HOSTNAME = "-.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞSSÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ÷ØÙÚÛÜÝÞŸàáâãäåæçèéêëìíîïðñòóôõö×øùúûüýþssàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ" ) func ParseEmail(email string) (bool, string) { @@ -102,5 +102,4 @@ func ParseEmail(email string) (bool, string) { valid = false } return valid, address - } diff --git a/nibbler_test.go b/nibbler_test.go index 2c8638b..db3b4b1 100644 --- a/nibbler_test.go +++ b/nibbler_test.go @@ -11,10 +11,11 @@ type example struct { var examples = []example{ example{"woo", false, "woo"}, example{"woo@woot.com", true, "woo@woot.com"}, + example{"hoot@hoot-hoot.com", true, "hoot@hoot-hoot.com"}, example{"woo/+@blah.com", true, "woo/+@blah.com"}, example{"#!$%&'*+-/=?^_`{}|~@example.org", true, "#!$%&'*+-/=?^_`{}|~@example.org"}, + example{"üñîçøðé@üñîçøðé.com", true, "üñîçøðé@üñîçøðé.com"}, example{"\"Bob\" ", false, "\"Bob\""}, - // example{"bobthebuilder@176.2.0.234", false, "bobthebuilder@176.2.0.234"}, } func TestNibbler(t *testing.T) { From 3380b02dfea0e54e38711d852f30ad465410e7c4 Mon Sep 17 00:00:00 2001 From: Ryan McDonald Date: Tue, 5 May 2015 09:06:32 -0600 Subject: [PATCH 2/5] QRA-784: Validate for double dots and spaces --- nibbler.go | 24 ++++++++++++++++++------ nibbler_test.go | 10 ++++++++++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/nibbler.go b/nibbler.go index 6a4f4ce..a1b868c 100644 --- a/nibbler.go +++ b/nibbler.go @@ -1,8 +1,6 @@ package go_nibbler -import ( - "strings" -) +import "strings" type state struct { InQuotes, PreviousDot, PreviousSlash, InDomain bool @@ -24,7 +22,10 @@ func ParseEmail(email string) (bool, string) { for offset, character := range email { // Local part if !currentState.InDomain { - if character == '\\' { + if character == ' ' { + valid = false + break + } else if character == '\\' { if currentState.InQuotes { // Check if slash was backslashed within quotes if currentState.PreviousSlash { @@ -38,13 +39,11 @@ func ParseEmail(email string) (bool, string) { break } } else if character == '"' { - if currentState.InQuotes { // Ignore if it was preceded by a backslash if !currentState.PreviousSlash { currentState.InQuotes = false } else { - // else: currentState.PreviousSlash = false } } else { @@ -58,6 +57,10 @@ func ParseEmail(email string) (bool, string) { } } else if character == '.' { // We can't have two consecutive dots + if !currentState.InQuotes && currentState.PreviousDot { + valid = false + break + } if !currentState.InQuotes { currentState.PreviousDot = true } @@ -90,6 +93,15 @@ func ParseEmail(email string) (bool, string) { currentState.PreviousDot = false } } else { + if character == '.' { + // We can't have two consecutive dots, even in the domain + if currentState.PreviousDot { + valid = false + break + } else { + currentState.PreviousDot = true + } + } if !strings.ContainsRune(HOSTNAME, character) { valid = false break diff --git a/nibbler_test.go b/nibbler_test.go index db3b4b1..8ac1f9b 100644 --- a/nibbler_test.go +++ b/nibbler_test.go @@ -16,6 +16,16 @@ var examples = []example{ example{"#!$%&'*+-/=?^_`{}|~@example.org", true, "#!$%&'*+-/=?^_`{}|~@example.org"}, example{"üñîçøðé@üñîçøðé.com", true, "üñîçøðé@üñîçøðé.com"}, example{"\"Bob\" ", false, "\"Bob\""}, + example{"really.long.but.vaild.address@example.com", true, "really.long.but.vaild.address@example.com"}, + example{"Bob bobthebuilder@dlc.com", false, "Bob"}, + example{"A@b@c@example.com", false, "A@b"}, + example{"a\"b(c)d,e:f;gi[j\\k]l@example.com", false, "a"}, + example{"[j\\k]l@example.com", false, ""}, + example{"john..doe@example.com", false, "john."}, + example{"john......doe@example.com", false, "john."}, + example{"john.doe@example..com", false, "john.doe@example."}, + example{" johndoe@example.com", false, ""}, + example{"johndoe@example.com ", false, "johndoe@example.com"}, } func TestNibbler(t *testing.T) { From 14055c5075357a97de7dda1820cac4e698f1d43d Mon Sep 17 00:00:00 2001 From: Ryan McDonald Date: Tue, 5 May 2015 16:20:08 -0600 Subject: [PATCH 3/5] QRA-784: Allow multiple dots in domains --- nibbler.go | 8 ++++++++ nibbler_test.go | 1 + 2 files changed, 9 insertions(+) diff --git a/nibbler.go b/nibbler.go index a1b868c..6a372c7 100644 --- a/nibbler.go +++ b/nibbler.go @@ -108,6 +108,14 @@ func ParseEmail(email string) (bool, string) { } else { address += string(character) } + + // Check states and clear them if necessary + if currentState.PreviousSlash && character != '\\' { + currentState.PreviousSlash = false + } + if currentState.PreviousDot && character != '.' { + currentState.PreviousDot = false + } } } if !currentState.InDomain { diff --git a/nibbler_test.go b/nibbler_test.go index 8ac1f9b..eefffde 100644 --- a/nibbler_test.go +++ b/nibbler_test.go @@ -17,6 +17,7 @@ var examples = []example{ example{"üñîçøðé@üñîçøðé.com", true, "üñîçøðé@üñîçøðé.com"}, example{"\"Bob\" ", false, "\"Bob\""}, example{"really.long.but.vaild.address@example.com", true, "really.long.but.vaild.address@example.com"}, + example{"johndoe@example.co.uk", true, "johndoe@example.co.uk"}, example{"Bob bobthebuilder@dlc.com", false, "Bob"}, example{"A@b@c@example.com", false, "A@b"}, example{"a\"b(c)d,e:f;gi[j\\k]l@example.com", false, "a"}, From ee9d038c3618897f33c5aff08819d310fc8506b8 Mon Sep 17 00:00:00 2001 From: Ryan McDonald Date: Mon, 15 Jun 2015 10:52:35 -0600 Subject: [PATCH 4/5] =?UTF-8?q?QRA-953:=20Add=20=C4=B1=20character=20to=20?= =?UTF-8?q?whitelist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nibbler.go | 2 +- nibbler_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nibbler.go b/nibbler.go index 6a4f4ce..0c07d04 100644 --- a/nibbler.go +++ b/nibbler.go @@ -13,7 +13,7 @@ const () const ( ATEXT = "!#$%&'*+-/=?^_`.{|}~@\"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞSSÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ÷ØÙÚÛÜÝÞŸàáâãäåæçèéêëìíîïðñòóôõö×øùúûüýþssàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ" SPECIAL = "(),:;<>[\\] " - HOSTNAME = "-.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞSSÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ÷ØÙÚÛÜÝÞŸàáâãäåæçèéêëìíîïðñòóôõö×øùúûüýþssàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ" + HOSTNAME = "-.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞSSÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ÷ØÙÚÛÜÝÞŸàáâãäåæçèéêëìíîïðñòóôõö×øùúûüýþssàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿı" ) func ParseEmail(email string) (bool, string) { diff --git a/nibbler_test.go b/nibbler_test.go index db3b4b1..5c3d639 100644 --- a/nibbler_test.go +++ b/nibbler_test.go @@ -14,7 +14,7 @@ var examples = []example{ example{"hoot@hoot-hoot.com", true, "hoot@hoot-hoot.com"}, example{"woo/+@blah.com", true, "woo/+@blah.com"}, example{"#!$%&'*+-/=?^_`{}|~@example.org", true, "#!$%&'*+-/=?^_`{}|~@example.org"}, - example{"üñîçøðé@üñîçøðé.com", true, "üñîçøðé@üñîçøðé.com"}, + example{"üñîçøðé@üñîçøðéı.com", true, "üñîçøðé@üñîçøðéı.com"}, example{"\"Bob\" ", false, "\"Bob\""}, } From 4ee90e1cf15eae398b4f7631151a0349d2bdf7a7 Mon Sep 17 00:00:00 2001 From: Ryan McDonald Date: Wed, 2 Mar 2016 10:54:43 -0700 Subject: [PATCH 5/5] Update test cases --- nibbler_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/nibbler_test.go b/nibbler_test.go index 86c344f..8f24cba 100644 --- a/nibbler_test.go +++ b/nibbler_test.go @@ -25,6 +25,7 @@ var examples = []example{ example{"john..doe@example.com", false, "john."}, example{"john......doe@example.com", false, "john."}, example{"john.doe@example..com", false, "john.doe@example."}, + example{"john.doe@exam_ple.com", false, "john.doe@exam"}, example{" johndoe@example.com", false, ""}, example{"johndoe@example.com ", false, "johndoe@example.com"}, }