7be0db04d8
* fix(backend): strip non-ASCII chars from branch/worktree names Non-ASCII titles (CJK, Cyrillic, Arabic, emoji) flowed verbatim into git branch names and worktree directory names because the sanitizers used unicode.IsLetter/IsDigit, which accept any Unicode letter or digit. The resulting names broke many downstream tools and left worktrees effectively inaccessible. Restrict SanitizeForBranch and SanitizeRepoDirName to ASCII alphanumerics. Non-ASCII runes now route through the existing hyphen-replace + collapse + trim pipeline, and the existing fallback chain (sanitized title -> sanitized task ID -> "task") handles titles that become empty after stripping. The "Issue #N:" / "PR #N:" prefix already added by the GitHub ingestion path means a non-ASCII issue title still produces a recognizable name like "issue-123". Closes #1081 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * refactor(worktree): fix comment accuracy and harden test assertion - Remove "emoji" from isASCIIAlphaNum doc — emoji are not Unicode letters (unicode.IsLetter returns false), so the prior code never admitted bare emoji. Correct examples to CJK, Cyrillic, Arabic. - Replace hard-coded len(dirName) != 8 with strings.Contains check so the assertion stays correct if suffix length ever changes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Kandev Agent <agent@kandev.dev> Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
34 lines
835 B
Go
34 lines
835 B
Go
package worktree
|
|
|
|
import "testing"
|
|
|
|
func TestSanitizeRepoDirName(t *testing.T) {
|
|
cases := []struct {
|
|
in, want string
|
|
}{
|
|
{"widget-config", "widget-config"},
|
|
{"acme/widget-config", "acme-widget-config"},
|
|
{"acme/widget", "acme-widget"},
|
|
{"owner\\repo", "owner-repo"},
|
|
{"weird:name space", "weird-name-space"},
|
|
{"with..dots", "with..dots"},
|
|
{"trailing/", "trailing"},
|
|
{"/leading", "leading"},
|
|
{"a//b", "a-b"},
|
|
{"-a-b-", "a-b"},
|
|
{".hidden", "hidden"},
|
|
{"!@#$%", ""},
|
|
{"", ""},
|
|
{"under_score.dot-dash", "under_score.dot-dash"},
|
|
{"修复登录问题", ""},
|
|
{"acme/修复", "acme"},
|
|
{"🐛/repo", "repo"},
|
|
{"owner/répó", "owner-r-p"},
|
|
}
|
|
for _, c := range cases {
|
|
if got := SanitizeRepoDirName(c.in); got != c.want {
|
|
t.Errorf("SanitizeRepoDirName(%q) = %q, want %q", c.in, got, c.want)
|
|
}
|
|
}
|
|
}
|