Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

redact: an email that ends a sentence is masked

yetonee7ba8a38920c
diff --git a/internal/redact/email_tld_test.go b/internal/redact/email_tld_test.go
index 5228fc73d..259325881 100644
--- a/internal/redact/email_tld_test.go
+++ b/internal/redact/email_tld_test.go
@@ -38,3 +38,31 @@ func TestEmailNeedsAMailDomain(t *testing.T) {
}
}
}
+
+// An address that ends a sentence is masked: the dot after it was a
+// bound character, so "The user's email address is [email protected]." (Claude
+// Code's own line in every request) and "write to me at [email protected]."
+// went to the vendor as written, the rules masking nothing. A dot that
+// makes the address part of a longer name still keeps it as it is.
+func TestEmailBeforeAFullStop(t *testing.T) {
+ o := Options{Secrets: true, Personal: true}
+ for _, in := range []string{
+ "The user's email address is [email protected]. Use it only to identify the user.",
+ "The user's email address is [email protected].",
+ "write to me at [email protected].",
+ "ask [email protected]... she knows",
+ `{"text":"mail [email protected].\nthanks"}`,
+ } {
+ if out, n := Mask(in, o); n != 1 || strings.Contains(out, "@") {
+ t.Errorf("%q: %d masked: %q", in, n, out)
+ }
+ }
+ for _, in := range []string{
+ "[email protected] is a version",
+ } {
+ if out, n := Mask(in, o); n != 0 {
+ t.Errorf("%q: %d masked: %q", in, n, out)
+ }
+ }
+}
diff --git a/internal/redact/redact.go b/internal/redact/redact.go
index ba89d5a6f..060747c93 100644
--- a/internal/redact/redact.go
+++ b/internal/redact/redact.go
@@ -181,7 +181,7 @@ var rules = append([]rule{
`[ \t]*(?:[为為是][ \t]*[::]?|:)[ \t]*(?:\\?["'“「])?(` + secretCh + `{3,}[A-Za-z0-9_\-/+=~!@#%^&*])`),
fold: cjkCopulas, back: 24, ahead: 260, at: keyAt},
- {kind: "EMAIL", re: regexp.MustCompile(`[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}`), markers: []string{"@"}, bound: alnum + "._%+-", ok: realEmail, at: notUserinfo, cat: catPersonal},
+ {kind: "EMAIL", re: regexp.MustCompile(`[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}`), markers: []string{"@"}, bound: alnum + "_%+-", ok: realEmail, at: emailAt, cat: catPersonal},
{kind: "ID_CARD", re: regexp.MustCompile(`[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|1[0-2])(?:0[1-9]|[12]\d|3[01])\d{3}[\dXx]`), bound: alnum, ok: chineseID, cat: catPersonal},
{kind: "PHONE", re: regexp.MustCompile(`(?:\+?86[- ]?)?1[3-9]\d{9}`), bound: digits, cat: catPersonal},
{kind: "BANK_CARD", re: regexp.MustCompile(`[3-6]\d{3}(?:[ -]?\d{4}){2,3}(?:[ -]?\d{1,3})?`), bound: digits, ok: luhn, cat: catPersonal},
@@ -356,6 +356,23 @@ func notUserinfo(s string, a, _ int) bool {
return !inUserinfo(s, a)
}
+// emailAt is where an email at s[a:b] can be: not in a URL's userinfo
+// (notUserinfo), and with no dot touching it that makes it part of a
+// longer name: none before it, and none after it that a letter, digit,
+// - or _ follows ([email protected] is no address). A dot after it that ends a
+// sentence is the sentence's: "The user's email address is
+// [email protected]." masked nothing while the dot was a bound character, and
+// the address went to the vendor as written.
+func emailAt(s string, a, b int) bool {
+ if a > 0 && s[a-1] == '.' {
+ return false
+ }
+ if b+1 < len(s) && s[b] == '.' && strings.IndexByte(tokenCh, s[b+1]) >= 0 {
+ return false
+ }
+ return notUserinfo(s, a, b)
+}
+
// inUserinfo says s[a] is inside a URL's authority, after its scheme://
// and before the host: nothing from there back to the // is a /, ?, #,
// space, quote, < or > or @.