Skip to content

Commit

Permalink
authres: Don't quote address-like property values
Browse files Browse the repository at this point in the history
  • Loading branch information
foxcpp authored and emersion committed Oct 21, 2019
1 parent 74b0c47 commit 56e7fdd
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions authres/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,26 @@ func formatValue(s string) string {
}

if shouldQuote {
// None of involved specs specify how to handle " in quoted strings
// so we just drop them and hope they are not criticial.
return `"` + strings.Replace(s, `"`, ``, -1) + `"`
return `"` + strings.Replace(s, `"`, `\"`, -1) + `"`
}
return s
}

var addressOk = map[rune]struct{}{
// Most ASCII punctuation except for:
// ( ) = "
// as these can cause issues due to ambiguous ABNF rules.
// I.e. technically mentioned characters can be left unquoted, but they can
// be interpreted as parts of non-quoted parameters or comments so it is
// better to quote them.
'#': {}, '$': {}, '%': {}, '&': {},
'\'': {}, '*': {}, '+': {}, ',': {},
'.': {}, '/': {}, '-': {}, '@': {},
'[': {}, ']': {}, '\\': {}, '^': {},
'_': {}, '`': {}, '{': {}, '|': {},
'}': {}, '~': {},
}

func formatPvalue(s string) string {
// pvalue = [CFWS] ( value / [ [ local-part ] "@" ] domain-name )
// [CFWS]
Expand All @@ -129,7 +142,7 @@ func formatPvalue(s string) string {
// for others.
addressLike := true
for _, ch := range s {
if !unicode.IsLetter(ch) && !unicode.IsDigit(ch) || ch != '@' {
if _, ok := addressOk[ch]; !unicode.IsLetter(ch) && !unicode.IsDigit(ch) && !ok {
addressLike = false
}
}
Expand Down

0 comments on commit 56e7fdd

Please sign in to comment.