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
}