From 2dcd3457c1a145750fe1c6bab5918320fe130230 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Wed, 18 Nov 2026 14:31:27 -0500 Subject: [PATCH] [scanner] fix: filter em-dashes in agent GitHub writes through the egress proxy Co-Authored-By: Claude Sonnet 5.5 Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Co-authored-by: clubanderson <407614+clubanderson@users.noreply.github.com> --- changelog.d/fixed-proxy-dash-filter.md | 1 + src/crux/config/proxy_dash_filter.go | 21 ++ src/crux/prosefilter/prosefilter.go | 210 +++++++++++++++++ .../prosefilter/prosefilter_test.go | 0 src/crux/proxy/dash_filter.go | 126 +++++++++++ src/crux/proxy/dash_filter_test.go | 82 +++++++ src/crux/proxy/github_proxy_mitm.go | 5 + src/pkg/prosefilter/emit_guard_test.go | 5 + src/pkg/prosefilter/prosefilter.go | 214 +----------------- 9 files changed, 460 insertions(+), 204 deletions(-) create mode 100644 changelog.d/fixed-proxy-dash-filter.md create mode 100644 src/crux/config/proxy_dash_filter.go create mode 100644 src/crux/prosefilter/prosefilter.go rename src/{pkg => crux}/prosefilter/prosefilter_test.go (100%) create mode 100644 src/crux/proxy/dash_filter.go create mode 100644 src/crux/proxy/dash_filter_test.go diff --git a/changelog.d/fixed-proxy-dash-filter.md b/changelog.d/fixed-proxy-dash-filter.md new file mode 100644 index 0000000000..c564d87ddb --- /dev/null +++ b/changelog.d/fixed-proxy-dash-filter.md @@ -0,0 +1 @@ +- The GitHub egress proxy now rewrites em-dashes in the text fields of agent-written GitHub JSON requests (comments, reviews, PR and issue titles and bodies), using the shared filter now in `crux/prosefilter`; set `HIVE_PROXY_DASH_FILTER=off` to disable (#19103). diff --git a/src/crux/config/proxy_dash_filter.go b/src/crux/config/proxy_dash_filter.go new file mode 100644 index 0000000000..bb9ed85cb1 --- /dev/null +++ b/src/crux/config/proxy_dash_filter.go @@ -0,0 +1,21 @@ +package config + +import ( + "os" + "strings" +) + +// ProxyDashFilterEnv switches the GitHub egress proxy's outbound dash filter. +// The filter is on by default; set this to "off" (or "false", "0") to forward +// agent write bodies unchanged. +const ProxyDashFilterEnv = "HIVE_PROXY_DASH_FILTER" + +// ProxyDashFilter reports whether the proxy rewrites em-dashes in the text +// fields of agent-originated GitHub JSON writes. Default on. +func ProxyDashFilter() bool { + switch strings.ToLower(strings.TrimSpace(os.Getenv(ProxyDashFilterEnv))) { + case "off", "false", "0", "no": + return false + } + return true +} diff --git a/src/crux/prosefilter/prosefilter.go b/src/crux/prosefilter/prosefilter.go new file mode 100644 index 0000000000..5a3b008fec --- /dev/null +++ b/src/crux/prosefilter/prosefilter.go @@ -0,0 +1,210 @@ +// Package prosefilter is the one place hive rewrites dashes in text that +// leaves the hive for a forge (PR and issue titles and bodies, comments, +// review bodies, commit messages). +// +// The owner's rule is that em-dashes are never acceptable in anything hive or +// its agents write. Agents are told so in the shared base prompt, but a model +// can still emit one, so every outward write path also passes its prose +// through Sanitize before it is sent. +// +// Sanitize rewrites only prose. Fenced code blocks, inline code spans and +// Markdown blockquote lines are left byte-for-byte alone, because they carry +// quoted or pasted content (a diff, a log line, a file excerpt) that must not +// be altered. +package prosefilter + +import ( + "regexp" + "strings" +) + +const ( + emDash = "\u2014" + enDash = "\u2013" + + // plainDash is what a dash used as punctuation becomes. + plainDash = "-" + // spacedDash is the replacement between two words. + spacedDash = " - " + + // maxFenceIndent is the Markdown limit on leading spaces for a code fence. + maxFenceIndent = 3 + // minFenceRun is the shortest run of fence characters that opens a fence. + minFenceRun = 3 +) + +var ( + // emDashRE matches an em-dash with the horizontal whitespace around it. + emDashRE = regexp.MustCompile(`[ \t]*` + emDash + `[ \t]*`) + // spacedEnDashRE matches an en-dash used as a dash (whitespace on both + // sides). An en-dash in a range such as 3-5 has no spaces and is left alone + // here; a hard-coded range is fixed at its source. + spacedEnDashRE = regexp.MustCompile(`[ \t]+` + enDash + `[ \t]+`) +) + +// HasDash reports whether s contains an em-dash or an en-dash. +func HasDash(s string) bool { + return strings.Contains(s, emDash) || strings.Contains(s, enDash) +} + +// Sanitize replaces every em-dash (U+2014), and every en-dash (U+2013) used +// as a spaced dash, in the prose of s with a plain hyphen. Text inside fenced +// code blocks, inline code spans and blockquote lines is untouched. A string +// with no such dash is returned unchanged. +func Sanitize(s string) string { + if !HasDash(s) { + return s + } + lines := strings.Split(s, "\n") + var fenceChar byte + var fenceLen int + for i, line := range lines { + if fenceChar != 0 { + if closesFence(line, fenceChar, fenceLen) { + fenceChar, fenceLen = 0, 0 + } + continue + } + if c, n := opensFence(line); c != 0 { + fenceChar, fenceLen = c, n + continue + } + if isBlockquote(line) { + continue + } + lines[i] = sanitizeLine(line) + } + return strings.Join(lines, "\n") +} + +// SanitizeTitle is Sanitize for a single-line title. A title has no code +// fence or blockquote, so only inline code spans are protected. +func SanitizeTitle(s string) string { + if !HasDash(s) { + return s + } + return sanitizeLine(s) +} + +func opensFence(line string) (byte, int) { + trimmed := strings.TrimLeft(line, " ") + if len(line)-len(trimmed) > maxFenceIndent || trimmed == "" { + return 0, 0 + } + c := trimmed[0] + if c != '`' && c != '~' { + return 0, 0 + } + n := runLen(trimmed, 0, c) + if n < minFenceRun { + return 0, 0 + } + // A backtick fence's info string may not contain a backtick; such a line + // is an inline code span, not a fence. + if c == '`' && strings.Contains(trimmed[n:], "`") { + return 0, 0 + } + return c, n +} + +func closesFence(line string, c byte, openLen int) bool { + trimmed := strings.TrimLeft(line, " ") + if len(line)-len(trimmed) > maxFenceIndent || trimmed == "" || trimmed[0] != c { + return false + } + n := runLen(trimmed, 0, c) + return n >= openLen && strings.TrimSpace(trimmed[n:]) == "" +} + +func isBlockquote(line string) bool { + return strings.HasPrefix(strings.TrimLeft(line, " "), ">") +} + +func runLen(s string, from int, c byte) int { + n := 0 + for from+n < len(s) && s[from+n] == c { + n++ + } + return n +} + +// sanitizeLine rewrites one prose line, skipping inline code spans. +func sanitizeLine(line string) string { + if !HasDash(line) { + return line + } + indentLen := len(line) - len(strings.TrimLeft(line, " \t")) + indent, rest := line[:indentLen], line[indentLen:] + + var b strings.Builder + b.WriteString(indent) + segStart := 0 + flush := func(end int) { + if end > segStart { + b.WriteString(rewriteSegment(rest[segStart:end], segStart == 0, end == len(rest))) + } + } + for i := 0; i < len(rest); { + if rest[i] != '`' { + i++ + continue + } + n := runLen(rest, i, '`') + closeAt := findClosingRun(rest, i+n, n) + if closeAt < 0 { + i += n + continue + } + flush(i) + spanEnd := closeAt + n + b.WriteString(rest[i:spanEnd]) + segStart = spanEnd + i = spanEnd + } + flush(len(rest)) + return b.String() +} + +// findClosingRun returns the index of the next run of exactly n backticks at +// or after from, or -1. +func findClosingRun(s string, from, n int) int { + for i := from; i < len(s); { + if s[i] != '`' { + i++ + continue + } + m := runLen(s, i, '`') + if m == n { + return i + } + i += m + } + return -1 +} + +// rewriteSegment replaces dashes in one non-code stretch of a line. atStart +// and atEnd say whether the segment touches the start or end of the line's +// prose, so a leading or trailing dash does not leave a stray space. +func rewriteSegment(seg string, atStart, atEnd bool) string { + seg = spacedEnDashRE.ReplaceAllString(seg, spacedDash) + locs := emDashRE.FindAllStringIndex(seg, -1) + if len(locs) == 0 { + return seg + } + var b strings.Builder + prev := 0 + for _, loc := range locs { + b.WriteString(seg[prev:loc[0]]) + switch { + case loc[0] == 0 && atStart: + b.WriteString(plainDash + " ") + case loc[1] == len(seg) && atEnd: + b.WriteString(" " + plainDash) + default: + b.WriteString(spacedDash) + } + prev = loc[1] + } + b.WriteString(seg[prev:]) + return b.String() +} diff --git a/src/pkg/prosefilter/prosefilter_test.go b/src/crux/prosefilter/prosefilter_test.go similarity index 100% rename from src/pkg/prosefilter/prosefilter_test.go rename to src/crux/prosefilter/prosefilter_test.go diff --git a/src/crux/proxy/dash_filter.go b/src/crux/proxy/dash_filter.go new file mode 100644 index 0000000000..8a5932555c --- /dev/null +++ b/src/crux/proxy/dash_filter.go @@ -0,0 +1,126 @@ +package proxy + +import ( + "bytes" + "encoding/json" + "io" + "net/http" + "strings" + + "github.com/hivecommons/hive/crux/config" + "github.com/hivecommons/hive/crux/prosefilter" +) + +// maxDashFilterBody bounds how much of a request body is buffered for +// rewriting. Larger bodies are forwarded untouched. +const maxDashFilterBody = 4 << 20 + +// filterOutboundDashes rewrites em-dashes in the text fields (body, title, +// message, review comments[].body, and the body/title inputs of GraphQL +// mutations) of an agent-originated GitHub JSON write, so an agent's own +// `gh api` call cannot put one on GitHub. Non-JSON bodies, other fields and +// git traffic are left alone. Content-Length is recomputed. It logs counts +// only, never the text. +func (p *GitHubProxy) filterOutboundDashes(req *http.Request, agentName string) { + if !config.ProxyDashFilter() || req.Body == nil || req.Body == http.NoBody { + return + } + switch req.Method { + case http.MethodPost, http.MethodPut, http.MethodPatch: + default: + return + } + if isGitPath(req.URL.Path) || !strings.Contains(strings.ToLower(req.Header.Get("Content-Type")), "json") { + return + } + if req.ContentLength < 0 || req.ContentLength > maxDashFilterBody { + return + } + raw, err := io.ReadAll(req.Body) + _ = req.Body.Close() + if err != nil { + // Partial read: forward what we have rather than dropping bytes. + req.Body = io.NopCloser(bytes.NewReader(raw)) + return + } + out, n := rewriteJSONDashes(raw, strings.HasSuffix(req.URL.Path, "/graphql")) + if n > 0 { + raw = out + req.Header.Del("Content-Length") + if p.logger != nil { + p.logger.Debug("proxy dash filter rewrote text fields", "agent", agentName, "fields", n) + } + } + req.Body = io.NopCloser(bytes.NewReader(raw)) + req.ContentLength = int64(len(raw)) +} + +// rewriteJSONDashes returns the body with dashes rewritten and the number of +// fields changed. Unparseable or unchanged input is returned as is. +func rewriteJSONDashes(raw []byte, graphql bool) ([]byte, int) { + dec := json.NewDecoder(bytes.NewReader(raw)) + dec.UseNumber() + var doc any + if err := dec.Decode(&doc); err != nil { + return raw, 0 + } + if _, err := dec.Token(); err != io.EOF { + return raw, 0 + } + obj, ok := doc.(map[string]any) + if !ok { + return raw, 0 + } + n := rewriteTextFields(obj, true) + if graphql { + if vars, ok := obj["variables"].(map[string]any); ok { + n += rewriteTextFields(vars, false) + for _, v := range vars { + if in, ok := v.(map[string]any); ok { + n += rewriteTextFields(in, false) + } + } + } + } + if n == 0 { + return raw, 0 + } + var buf bytes.Buffer + enc := json.NewEncoder(&buf) + enc.SetEscapeHTML(false) + if err := enc.Encode(obj); err != nil { + return raw, 0 + } + return bytes.TrimRight(buf.Bytes(), "\n"), n +} + +func rewriteTextFields(obj map[string]any, reviewComments bool) int { + n := 0 + for key, sanitize := range map[string]func(string) string{ + "body": prosefilter.Sanitize, + "title": prosefilter.SanitizeTitle, + "message": prosefilter.Sanitize, + } { + if s, ok := obj[key].(string); ok { + if r := sanitize(s); r != s { + obj[key] = r + n++ + } + } + } + if reviewComments { + if list, ok := obj["comments"].([]any); ok { + for _, item := range list { + if c, ok := item.(map[string]any); ok { + if s, ok := c["body"].(string); ok { + if r := prosefilter.Sanitize(s); r != s { + c["body"] = r + n++ + } + } + } + } + } + } + return n +} diff --git a/src/crux/proxy/dash_filter_test.go b/src/crux/proxy/dash_filter_test.go new file mode 100644 index 0000000000..e4b0260b06 --- /dev/null +++ b/src/crux/proxy/dash_filter_test.go @@ -0,0 +1,82 @@ +package proxy + +import ( + "net/http" + "net/http/httptest" + "strings" + "testing" +) + +const testEm = "\u2014" + +func filterReq(t *testing.T, method, path, ctype, body string) (*http.Request, string) { + t.Helper() + req := httptest.NewRequest(method, "https://api.github.com"+path, strings.NewReader(body)) + if ctype != "" { + req.Header.Set("Content-Type", ctype) + } + p := &GitHubProxy{} + p.filterOutboundDashes(req, "agent") + b := new(strings.Builder) + buf := make([]byte, 4096) + for { + n, err := req.Body.Read(buf) + b.Write(buf[:n]) + if err != nil { + break + } + } + if int64(b.Len()) != req.ContentLength { + t.Fatalf("ContentLength %d != body %d", req.ContentLength, b.Len()) + } + return req, b.String() +} + +func TestFilterOutboundDashesComment(t *testing.T) { + _, got := filterReq(t, "POST", "/repos/o/r/issues/1/comments", "application/json", + `{"body":"a `+testEm+` b\n`+"```"+`\nx `+testEm+` y\n`+"```"+`","n":1}`) + if strings.Contains(strings.Split(got, "```")[0], testEm) || !strings.Contains(got, "a - b") { + t.Fatalf("prose not rewritten: %s", got) + } + if !strings.Contains(got, "x "+testEm+" y") { + t.Fatalf("code block altered: %s", got) + } +} + +func TestFilterOutboundDashesReviewAndGraphQL(t *testing.T) { + _, got := filterReq(t, "POST", "/repos/o/r/pulls/1/reviews", "application/json", + `{"comments":[{"body":"a `+testEm+` b","path":"p"}],"title":"t `+testEm+` u"}`) + if strings.Contains(got, testEm) { + t.Fatalf("review not rewritten: %s", got) + } + _, got = filterReq(t, "POST", "/graphql", "application/json", + `{"query":"mutation{x}","variables":{"input":{"body":"a `+testEm+` b"}}}`) + if strings.Contains(got, testEm) { + t.Fatalf("graphql not rewritten: %s", got) + } +} + +func TestFilterOutboundDashesLeavesOthersAlone(t *testing.T) { + for _, tc := range []struct{ method, path, ctype string }{ + {"POST", "/repos/o/r/issues/1/comments", "text/plain"}, + {"POST", "/o/r.git/git-receive-pack", "application/json"}, + {"GET", "/repos/o/r", "application/json"}, + } { + body := `{"body":"a ` + testEm + ` b"}` + if _, got := filterReq(t, tc.method, tc.path, tc.ctype, body); got != body { + t.Fatalf("%v changed body: %s", tc, got) + } + } + _, got := filterReq(t, "POST", "/x", "application/json", `{"other":"a `+testEm+` b"}`) + if !strings.Contains(got, testEm) { + t.Fatalf("non-text field altered: %s", got) + } +} + +func TestFilterOutboundDashesSwitchOff(t *testing.T) { + t.Setenv("HIVE_PROXY_DASH_FILTER", "off") + body := `{"body":"a ` + testEm + ` b"}` + if _, got := filterReq(t, "POST", "/repos/o/r/issues/1/comments", "application/json", body); got != body { + t.Fatalf("switch off changed body: %s", got) + } +} diff --git a/src/crux/proxy/github_proxy_mitm.go b/src/crux/proxy/github_proxy_mitm.go index 37ed4cabbb..58e8ca0917 100644 --- a/src/crux/proxy/github_proxy_mitm.go +++ b/src/crux/proxy/github_proxy_mitm.go @@ -379,6 +379,11 @@ func (p *GitHubProxy) proxyHTTPHost(client net.Conn, upstream net.Conn, host str return } + // Agent-written text must not carry em-dashes onto GitHub (#19103). + if injectsGitHubAuthForHost(host) { + p.filterOutboundDashes(req, agentName) + } + // Forward to upstream. The client read deadline stays in force until // the body is fully drained (req.Write pipes req.Body from the client), // so a client stalling mid-body cannot hang the relay. diff --git a/src/pkg/prosefilter/emit_guard_test.go b/src/pkg/prosefilter/emit_guard_test.go index ab0882ecb7..510db92473 100644 --- a/src/pkg/prosefilter/emit_guard_test.go +++ b/src/pkg/prosefilter/emit_guard_test.go @@ -11,6 +11,11 @@ import ( "testing" ) +const ( + emDash = "\u2014" + enDash = "\u2013" +) + // emitDirs are the source trees (relative to src/) whose non-test Go files // build text that hive sends to a forge or an agent: PR, issue and comment // templates, status lines, notices and kick prompts. Docs, tests and diff --git a/src/pkg/prosefilter/prosefilter.go b/src/pkg/prosefilter/prosefilter.go index 5a3b008fec..8cb704d372 100644 --- a/src/pkg/prosefilter/prosefilter.go +++ b/src/pkg/prosefilter/prosefilter.go @@ -1,210 +1,16 @@ -// Package prosefilter is the one place hive rewrites dashes in text that -// leaves the hive for a forge (PR and issue titles and bodies, comments, -// review bodies, commit messages). -// -// The owner's rule is that em-dashes are never acceptable in anything hive or -// its agents write. Agents are told so in the shared base prompt, but a model -// can still emit one, so every outward write path also passes its prose -// through Sanitize before it is sent. -// -// Sanitize rewrites only prose. Fenced code blocks, inline code spans and -// Markdown blockquote lines are left byte-for-byte alone, because they carry -// quoted or pasted content (a diff, a log line, a file excerpt) that must not -// be altered. +// Package prosefilter is the root-module entry point to the shared outbound +// dash filter. The implementation lives in crux/prosefilter so the GitHub +// egress proxy (nested crux module, which cannot import pkg/) and hive's own +// send paths use the same function. See crux/prosefilter for the rules. package prosefilter -import ( - "regexp" - "strings" -) - -const ( - emDash = "\u2014" - enDash = "\u2013" - - // plainDash is what a dash used as punctuation becomes. - plainDash = "-" - // spacedDash is the replacement between two words. - spacedDash = " - " - - // maxFenceIndent is the Markdown limit on leading spaces for a code fence. - maxFenceIndent = 3 - // minFenceRun is the shortest run of fence characters that opens a fence. - minFenceRun = 3 -) - -var ( - // emDashRE matches an em-dash with the horizontal whitespace around it. - emDashRE = regexp.MustCompile(`[ \t]*` + emDash + `[ \t]*`) - // spacedEnDashRE matches an en-dash used as a dash (whitespace on both - // sides). An en-dash in a range such as 3-5 has no spaces and is left alone - // here; a hard-coded range is fixed at its source. - spacedEnDashRE = regexp.MustCompile(`[ \t]+` + enDash + `[ \t]+`) -) +import cruxfilter "github.com/hivecommons/hive/crux/prosefilter" // HasDash reports whether s contains an em-dash or an en-dash. -func HasDash(s string) bool { - return strings.Contains(s, emDash) || strings.Contains(s, enDash) -} - -// Sanitize replaces every em-dash (U+2014), and every en-dash (U+2013) used -// as a spaced dash, in the prose of s with a plain hyphen. Text inside fenced -// code blocks, inline code spans and blockquote lines is untouched. A string -// with no such dash is returned unchanged. -func Sanitize(s string) string { - if !HasDash(s) { - return s - } - lines := strings.Split(s, "\n") - var fenceChar byte - var fenceLen int - for i, line := range lines { - if fenceChar != 0 { - if closesFence(line, fenceChar, fenceLen) { - fenceChar, fenceLen = 0, 0 - } - continue - } - if c, n := opensFence(line); c != 0 { - fenceChar, fenceLen = c, n - continue - } - if isBlockquote(line) { - continue - } - lines[i] = sanitizeLine(line) - } - return strings.Join(lines, "\n") -} - -// SanitizeTitle is Sanitize for a single-line title. A title has no code -// fence or blockquote, so only inline code spans are protected. -func SanitizeTitle(s string) string { - if !HasDash(s) { - return s - } - return sanitizeLine(s) -} - -func opensFence(line string) (byte, int) { - trimmed := strings.TrimLeft(line, " ") - if len(line)-len(trimmed) > maxFenceIndent || trimmed == "" { - return 0, 0 - } - c := trimmed[0] - if c != '`' && c != '~' { - return 0, 0 - } - n := runLen(trimmed, 0, c) - if n < minFenceRun { - return 0, 0 - } - // A backtick fence's info string may not contain a backtick; such a line - // is an inline code span, not a fence. - if c == '`' && strings.Contains(trimmed[n:], "`") { - return 0, 0 - } - return c, n -} - -func closesFence(line string, c byte, openLen int) bool { - trimmed := strings.TrimLeft(line, " ") - if len(line)-len(trimmed) > maxFenceIndent || trimmed == "" || trimmed[0] != c { - return false - } - n := runLen(trimmed, 0, c) - return n >= openLen && strings.TrimSpace(trimmed[n:]) == "" -} - -func isBlockquote(line string) bool { - return strings.HasPrefix(strings.TrimLeft(line, " "), ">") -} - -func runLen(s string, from int, c byte) int { - n := 0 - for from+n < len(s) && s[from+n] == c { - n++ - } - return n -} - -// sanitizeLine rewrites one prose line, skipping inline code spans. -func sanitizeLine(line string) string { - if !HasDash(line) { - return line - } - indentLen := len(line) - len(strings.TrimLeft(line, " \t")) - indent, rest := line[:indentLen], line[indentLen:] - - var b strings.Builder - b.WriteString(indent) - segStart := 0 - flush := func(end int) { - if end > segStart { - b.WriteString(rewriteSegment(rest[segStart:end], segStart == 0, end == len(rest))) - } - } - for i := 0; i < len(rest); { - if rest[i] != '`' { - i++ - continue - } - n := runLen(rest, i, '`') - closeAt := findClosingRun(rest, i+n, n) - if closeAt < 0 { - i += n - continue - } - flush(i) - spanEnd := closeAt + n - b.WriteString(rest[i:spanEnd]) - segStart = spanEnd - i = spanEnd - } - flush(len(rest)) - return b.String() -} +func HasDash(s string) bool { return cruxfilter.HasDash(s) } -// findClosingRun returns the index of the next run of exactly n backticks at -// or after from, or -1. -func findClosingRun(s string, from, n int) int { - for i := from; i < len(s); { - if s[i] != '`' { - i++ - continue - } - m := runLen(s, i, '`') - if m == n { - return i - } - i += m - } - return -1 -} +// Sanitize rewrites dashes in the prose of s. See crux/prosefilter.Sanitize. +func Sanitize(s string) string { return cruxfilter.Sanitize(s) } -// rewriteSegment replaces dashes in one non-code stretch of a line. atStart -// and atEnd say whether the segment touches the start or end of the line's -// prose, so a leading or trailing dash does not leave a stray space. -func rewriteSegment(seg string, atStart, atEnd bool) string { - seg = spacedEnDashRE.ReplaceAllString(seg, spacedDash) - locs := emDashRE.FindAllStringIndex(seg, -1) - if len(locs) == 0 { - return seg - } - var b strings.Builder - prev := 0 - for _, loc := range locs { - b.WriteString(seg[prev:loc[0]]) - switch { - case loc[0] == 0 && atStart: - b.WriteString(plainDash + " ") - case loc[1] == len(seg) && atEnd: - b.WriteString(" " + plainDash) - default: - b.WriteString(spacedDash) - } - prev = loc[1] - } - b.WriteString(seg[prev:]) - return b.String() -} +// SanitizeTitle is Sanitize for a single-line title. +func SanitizeTitle(s string) string { return cruxfilter.SanitizeTitle(s) }