阶段十:完成 Go 基础包注释基线清零

This commit is contained in:
Christ committed 2026-08-15 05:42:49 +08:00
1 parent ea1f2ec430
commit d1a165f897
14 files changed
+135 -924

No files matched your search

+4
View File
@@ -10,17 +10,21 @@ import (
)
// ID returns a short stable fingerprint for a sensitive identifier.
// ID 负责标识相关处理。
func ID(s string) string {
s = strings.TrimSpace(s)
if s == "" {
return ""
}
// sum 保存sum,供当前处理流程使用
sum := sha256.Sum256([]byte(s))
return hex.EncodeToString(sum[:])[:12]
}
// URL returns origin + path for URLs that may contain session tokens.
// URL 负责URL相关处理。
func URL(raw string) string {
// u、err 保存u、err,供当前处理流程使用
u, err := url.Parse(strings.TrimSpace(raw))
if err != nil || u.Scheme == "" || u.Host == "" {
return "<redacted>"
+5 -2
View File
@@ -2,6 +2,7 @@ package logsafe
import "testing"
// TestRedactionHelpers 负责TestRedactionHelpers相关处理。
func TestRedactionHelpers(t *testing.T) {
if ID(" secret ") != ID("secret") || len(ID("secret")) != 12 {
t.Fatal("ID should be trimmed, stable, and short")
@@ -9,10 +10,12 @@ func TestRedactionHelpers(t *testing.T) {
if ID("") != "" {
t.Fatal("empty ID should remain empty")
}
if got := URL("https://example.com/path?q=token#secret"); got != "https://example.com/path" {
if // got 保存got,供当前处理流程使用
got := URL("https://example.com/path?q=token#secret"); got != "https://example.com/path" {
t.Fatalf("URL leaked query or fragment: %q", got)
}
if got := URL("not-a-url"); got != "<redacted>" {
if // got 保存got,供当前处理流程使用
got := URL("not-a-url"); got != "<redacted>" {
t.Fatalf("invalid URL = %q", got)
}
}