()
| 206 | } |
| 207 | |
| 208 | func (f *HTMLForm) Hash() string { |
| 209 | hasher := md5.New() |
| 210 | |
| 211 | var parts []string |
| 212 | parts = append(parts, f.TagName) |
| 213 | |
| 214 | if f.ID != "" { |
| 215 | parts = append(parts, "id:"+f.ID) |
| 216 | } |
| 217 | if f.Classes != "" { |
| 218 | parts = append(parts, "class:"+f.Classes) |
| 219 | } |
| 220 | |
| 221 | // Add stable attributes |
| 222 | stableAttrs := getStableAttributes(f.Attributes) |
| 223 | for _, k := range stableAttrs { |
| 224 | parts = append(parts, fmt.Sprintf("%s:%s", k, f.Attributes[k])) |
| 225 | } |
| 226 | parts = append(parts, fmt.Sprintf("action:%s", f.Action), fmt.Sprintf("method:%s", f.Method)) |
| 227 | |
| 228 | // Include hashes of form elements |
| 229 | for _, element := range f.Elements { |
| 230 | parts = append(parts, element.Hash()) |
| 231 | } |
| 232 | |
| 233 | hashInput := strings.Join(parts, "|") |
| 234 | if IsDiagnosticEnabled { |
| 235 | fmt.Fprintf(os.Stderr, "[diagnostic] Form hash input: %s\n", hashInput) |
| 236 | } |
| 237 | hasher.Write([]byte(hashInput)) |
| 238 | return hex.EncodeToString(hasher.Sum(nil)) |
| 239 | } |
| 240 | |
| 241 | // getStableAttributes returns a sorted slice of attribute keys that are considered stable. |
| 242 | func getStableAttributes(attrs map[string]string) []string { |
nothing calls this directly
no test coverage detected