Files
magpie/internal/redact/email_tld_test.go
T
yetone e7ba8a3892 redact: an email that ends a sentence is masked
The EMAIL rule's bound characters held "." on both sides, so an
address followed by a full stop was no match: "The user's email
address is jo@quill.dev." (Claude Code's own userEmail line) and
"write to me at li.wei@qq.com." went to the vendor as written with
the rules on. Found measuring the local model's threshold for
Yayoi_no_yume on X: in 2000 segments of real Codex and Claude Code
traffic, two real addresses were masked only because a model found
them, at 0.70 and 0.95.

emailAt now judges a dot beside the match: one before it still turns
it away, and one after it only when a letter, digit, - or _ follows
(a@b.io.12 stays unmasked, as before). The rest of the bound
(letters, digits, _ % + -) is unchanged.

TestEmailBeforeAFullStop: its five sentence-end cases fail on the old
rule (5 of 5 unmasked), pass now; its two longer-name cases are
unmasked on both.
2026-10-27 17:10:20 +08:00

69 lines
2.5 KiB
Go

package redact
import (
"strings"
"testing"
)
// What follows the @ of a decorator or a module's attribute (pytest.fixture)
// ends in a word no registry has, and an agent's own files (AGENTS.md)
// end in .md: neither was an address, and both were masked (ydzh on
// Discord). Addresses on real domains, a company's own (.local, .corp)
// and the .md of a domain that isn't such a file are still masked.
func TestEmailNeedsAMailDomain(t *testing.T) {
o := Options{Secrets: true, Personal: true}
for _, s := range []string{
"xxx@Agents.md", "follow docs@AGENTS.md", "see repo@CLAUDE.md and x@README.md",
"x@pytest.fixture", "def@pytest.mark.parametrize", "conftest@pytest.mark.asyncio",
"cls@dataclasses.dataclass", "obj@functools.cache",
} {
in := "look at " + s + " now"
if out, n := Mask(in, o); n != 0 || out != in {
t.Errorf("%q: %d masked: %q", s, n, out)
}
}
for _, s := range []string{
"rina.k@fastmail.com", "dev@startup.io", "me@notes.md", "ops@corp.example.co.uk",
"x@company.ai", "li.wei@qq.com", "admin@build.local", "ops@mail.corp", "j@Gmail.COM",
} {
in := "mail " + s + " today"
if out, n := Mask(in, o); n != 1 || strings.Contains(out, s) {
t.Errorf("%q: %d masked: %q", s, n, out)
}
}
f := &fakeModel{values: map[string]string{"x@pytest.fixture": "private_email", "xxx@Agents.md": "private_email"}}
for _, s := range []string{"x@pytest.fixture", "xxx@Agents.md"} {
if out, n := Mask(s, Options{Personal: true, Model: f.find}); n != 0 {
t.Errorf("model's %q: %d masked: %q", s, n, out)
}
}
}
// An address that ends a sentence is masked: the dot after it was a
// bound character, so "The user's email address is jo@quill.dev." (Claude
// Code's own line in every request) and "write to me at li.wei@qq.com."
// 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 jo@quill.dev. Use it only to identify the user.",
"The user's email address is jo@quill.dev.",
"write to me at li.wei@qq.com.",
"ask rina.k@fastmail.com... she knows",
`{"text":"mail jo@quill.dev.\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{
"x@build.io.12 is a version",
"a@b.co.x_y",
} {
if out, n := Mask(in, o); n != 0 {
t.Errorf("%q: %d masked: %q", in, n, out)
}
}
}