fix(openflare): improve SWOfflineDomains validation and snapshot diff logic

This commit is contained in:
ryan
2026-08-08 20:52:07 +08:00
parent 6882481a56
commit 9797fcdb2f
8 changed files with 42 additions and 6 deletions
@@ -260,7 +260,7 @@ func validateSWOfflineHTML(key, value string) error {
func validateSWOfflineDomains(key, value string) error {
var domains []string
if err := json.Unmarshal([]byte(value), &domains); err != nil {
if err := json.Unmarshal([]byte(value), &domains); err != nil || domains == nil {
return fmt.Errorf("%s 必须为 JSON 字符串数组", key)
}
if len(domains) > maxSWOfflineDomains {
@@ -106,6 +106,7 @@ func TestValidateSWOfflineDomains(t *testing.T) {
{"single", `["example.com"]`, true},
{"multiple", `["example.com","api.example.com"]`, true},
{"invalid json", `not-json`, false},
{"null", "null", false},
{"empty element", `[""]`, false},
{"duplicate", `["example.com","example.com"]`, false},
{"whitespace dedup", `[" Example.com ","example.com"]`, false},