Skip to content

fix(form): fix infinite recursion when decoding self-referenced structs - #47

Merged
tatang26 merged 1 commit into
mainfrom
fix-form-decode-self-referenced-structs
Apr 16, 2026
Merged

fix(form): fix infinite recursion when decoding self-referenced structs#47
tatang26 merged 1 commit into
mainfrom
fix-form-decode-self-referenced-structs

Conversation

@tatang26

Copy link
Copy Markdown
Contributor

Summary

Fixes infinite recursion bug when decoding self-referenced structs in form data.

Problem

The form decoder recursively processed pointer fields even when no form data existed for them, causing infinite recursion on self-referencing types like:

type Node struct {
    ID     string
    Parent *Node  // Would recurse infinitely
}

Solution

Added form data existence check before recursing into struct pointer fields (form/decode.go:73-92):

  • Only processes nested structs when matching form data exists
  • Checks for form keys with the field's prefix
  • Properly handles anonymous fields

Testing

  • ✅ Self-referencing structs with/without data
  • ✅ Multiple nesting levels (3+ deep)
  • ✅ Tree structures and bidirectional links
  • ✅ Added benchmark for performance validation

@tatang26
tatang26 merged commit 3944424 into main Apr 16, 2026
1 check passed
@tatang26
tatang26 deleted the fix-form-decode-self-referenced-structs branch April 17, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant