Skip to content

Commit 2c64876

Browse files
committed
fix(service): trim dangling connectors from truncated help clauses
A clause cut can strand a connector — e.g. a colon introducing a list the newline cut drops, as in im.reactions.list's message_id — and the help-line joiner then renders "…获取方式:.". Extend inlineClause's trailing trim from sentence enders to stranded connectors (::,,、); mid-clause punctuation is untouched. Change-Id: Ibc0372c2faba033aca26d3089e1754a5e58c3448
1 parent a6ac36f commit 2c64876

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

cmd/service/paramhelp.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ var markdownLinkRe = regexp.MustCompile(`\[([^\]]*)\]\([^)]*\)`)
7474

7575
// inlineClause compresses metadata prose into one help clause: markdown links
7676
// keep their text, the clause cuts at the first rune in stops, whitespace
77-
// collapses, trailing sentence punctuation goes (the clause join adds its
78-
// own), and the result caps at max runes. The two policies below differ only
79-
// in where they cut and how much they keep.
77+
// collapses, trailing punctuation goes — sentence enders (the clause join adds
78+
// its own) and connectors a cut can strand, like a colon introducing a list the
79+
// newline cut dropped — and the result caps at max runes. The two policies
80+
// below differ only in where they cut and how much they keep.
8081
func inlineClause(s, stops string, max int) string {
8182
if s == "" {
8283
return ""
@@ -86,7 +87,7 @@ func inlineClause(s, stops string, max int) string {
8687
s = s[:i]
8788
}
8889
s = strings.Join(strings.Fields(s), " ")
89-
s = strings.TrimRight(s, "。.")
90+
s = strings.TrimRight(s, "。.::,,、")
9091
return util.TruncateStrWithEllipsis(s, max)
9192
}
9293

cmd/service/sanitize_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,19 @@ func TestSanitizeOptionDesc(t *testing.T) {
3232
t.Errorf("truncation = %q (%d runes), want 40 runes ending in ...", got, len(r))
3333
}
3434
}
35+
36+
func TestSanitizeFieldDesc_TrimsDanglingPunctuation(t *testing.T) {
37+
// A clause cut can strand a connector (e.g. a colon introducing a list the
38+
// newline cut drops, as in im.reactions.list's message_id); the help line
39+
// joiner then renders "…获取方式:." — so dangling punctuation must go too.
40+
cases := map[string]string{
41+
"待查询的消息ID。ID 获取方式:\n- 调用接口获取": "待查询的消息ID。ID 获取方式",
42+
"see the list below:\nitem": "see the list below",
43+
"逗号结尾,\n下一行": "逗号结尾",
44+
}
45+
for in, want := range cases {
46+
if got := sanitizeFieldDesc(in); got != want {
47+
t.Errorf("sanitizeFieldDesc(%q) = %q, want %q", in, got, want)
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)