使用了AI重构项目,并完善了一部分后台问题

This commit is contained in:
2026-08-05 04:47:11 +08:00
parent 146b6b1e6c
commit ac740c24fd
35 changed files with 2876 additions and 980 deletions
+42
View File
@@ -0,0 +1,42 @@
package api
import "testing"
func TestURLValidation(t *testing.T) {
for _, value := range []string{"https://example.com", "http://localhost:8080"} {
if !validHTTPURL(value) {
t.Errorf("expected valid site URL: %s", value)
}
}
for _, value := range []string{"javascript:alert(1)", "//example.com", "example.com"} {
if validHTTPURL(value) {
t.Errorf("expected invalid site URL: %s", value)
}
}
for _, value := range []string{"mailto:a@example.com", "tel:+8613800000000", "https://example.com"} {
if !validContactURL(value) {
t.Errorf("expected valid contact URL: %s", value)
}
}
for _, value := range []string{"/uploads/qr.png", "https://example.com/qr.png"} {
if !validQRCode(value) {
t.Errorf("expected valid QR path: %s", value)
}
}
for _, value := range []string{"/uploads/../secret.png", "data:image/png;base64,abc"} {
if validQRCode(value) {
t.Errorf("expected invalid QR path: %s", value)
}
}
}
func TestPercentageCountsSumsToOneHundred(t *testing.T) {
values := percentageCounts(map[string]int{"direct": 1, "search": 1, "other": 1}, 3)
total := 0
for _, value := range values {
total += value["value"].(int)
}
if total != 100 {
t.Fatalf("percentage total = %d, want 100", total)
}
}