Skip to content

Commit

Permalink
Merge pull request #9 from shiar/main
Browse files Browse the repository at this point in the history
endless loop following self referential structs
  • Loading branch information
ggicci committed Dec 17, 2023
2 parents 8fffb3d + 8814d32 commit e3644c4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,9 @@ func buildResolver(typ reflect.Type, field reflect.StructField, parent *Resolver
if !field.IsExported() {
continue
}
if field.Type == root.Type {
continue
}

child, err := buildResolver(field.Type, field, root)
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,14 @@ func TestNew_WithNonStruct(t *testing.T) {
assert.ErrorContains(t, err, "non-struct type")
}

func TestNew_WithRecursion(t *testing.T) {
type RecursiveRef struct {
Loop *RecursiveRef
}
_, err := owl.New(RecursiveRef{})
assert.NoError(t, err)
}

func TestNew_ParsingDirectives_InvalidName(t *testing.T) {
resolver, err := owl.New(struct {
Invalid string `owl:"invalid/name"`
Expand Down

0 comments on commit e3644c4

Please sign in to comment.