1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-17 17:47:03 +00:00

Checkpoint before converting Validator->Parser

This commit is contained in:
James Hillyerd
2013-11-04 14:00:23 -08:00
parent bd4db645bb
commit 21ad7a2452
2 changed files with 21 additions and 6 deletions

View File

@@ -105,6 +105,7 @@ func ValidateLocalPart(local string) bool {
prev := byte('.')
inCharQuote := false
inStringQuote := false
for i := 0; i < length; i++ {
c := local[i]
switch {
@@ -125,18 +126,25 @@ func ValidateLocalPart(local string) bool {
}
case c == '\\':
inCharQuote = true
case c == '"':
if inCharQuote {
inCharQuote = false
} else {
inStringQuote = !inStringQuote
}
case c > 127:
return false
default:
if ! inCharQuote {
return false
if inCharQuote || inStringQuote {
inCharQuote = false
return true
}
inCharQuote = false
return false
}
prev = c
}
if inCharQuote {
// Can't end with unused backslash quote
if inCharQuote || inStringQuote {
// Can't end with unused backslash quote or unterminated string quote
return false
}

View File

@@ -82,7 +82,14 @@ func TestValidateLocal(t *testing.T) {
{"one\\$\\|", true, "Should be able to quote plain specials"},
{"return\\\r", true, "Should be able to quote ASCII control chars"},
{"high\\\x80", false, "Should not accept > 7-bit quoted chars"},
//{"\"james\"", true, "Quoted a-z is permitted"},
{"quote\\\"", true, "Quoted double quote is permitted"},
{"\"james\"", true, "Quoted a-z is permitted"},
{"\"first last\"", true, "Quoted space is permitted"},
{"\"quoted@sign\"", true, "Quoted @ is allowed"},
{"\"qp\\\"quote\"", true, "Quoted quote within quoted string is OK"},
{"\"unterminated", false, "Quoted string must be terminated"},
{"\"unterminated\\\"", false, "Quoted string must be terminated"},
{"embed\"quote\"string", false, "Embedded quoted string is illegal"},
{"user+mailbox", true, "RFC3696 test case should be valid"},
{"customer/department=shipping", true, "RFC3696 test case should be valid"},