1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-18 18:17: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('.') prev := byte('.')
inCharQuote := false inCharQuote := false
inStringQuote := false
for i := 0; i < length; i++ { for i := 0; i < length; i++ {
c := local[i] c := local[i]
switch { switch {
@@ -125,18 +126,25 @@ func ValidateLocalPart(local string) bool {
} }
case c == '\\': case c == '\\':
inCharQuote = true inCharQuote = true
case c == '"':
if inCharQuote {
inCharQuote = false
} else {
inStringQuote = !inStringQuote
}
case c > 127: case c > 127:
return false return false
default: default:
if ! inCharQuote { if inCharQuote || inStringQuote {
return false
}
inCharQuote = false inCharQuote = false
return true
}
return false
} }
prev = c prev = c
} }
if inCharQuote { if inCharQuote || inStringQuote {
// Can't end with unused backslash quote // Can't end with unused backslash quote or unterminated string quote
return false return false
} }

View File

@@ -82,7 +82,14 @@ func TestValidateLocal(t *testing.T) {
{"one\\$\\|", true, "Should be able to quote plain specials"}, {"one\\$\\|", true, "Should be able to quote plain specials"},
{"return\\\r", true, "Should be able to quote ASCII control chars"}, {"return\\\r", true, "Should be able to quote ASCII control chars"},
{"high\\\x80", false, "Should not accept > 7-bit quoted 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"}, {"user+mailbox", true, "RFC3696 test case should be valid"},
{"customer/department=shipping", true, "RFC3696 test case should be valid"}, {"customer/department=shipping", true, "RFC3696 test case should be valid"},