aranGO icon indicating copy to clipboard operation
aranGO copied to clipboard

Tags : infinite loop

Open malletjo opened this issue 9 years ago • 1 comments

Let me know if i'm wrong :

func getTags(obj reflect.Type, tags map[string]string, key string) {

    if obj.Kind() != reflect.Struct && obj.Kind() != reflect.Ptr {
        return
    }

    var tag string

    fieldsCount := obj.NumField()

    for i := 0; i < fieldsCount; i++ {
        structField := obj.Field(i)
        if structField.Anonymous && structField.Type.Kind() == reflect.Struct {
            getTags(obj, tags, key)
        } else {
            tag = structField.Tag.Get(key)
            if tag != "" {
                tags[structField.Name] = tag
            }
        }
    }
}

So if it's another struct, it will call itself with the same tag (obj)

Result in a infinite loop (overflow)

Possible solution: replaced with structField.Type

getTags(structField.Type, tags, key)

=== Step to reproduce ===

In a model

type Model struct {
    aranGO.Document
}

type Event struct {
    Model
    Title string        `json:"title"`
}

The embedded struct should cause the SO

malletjo avatar Aug 29 '16 10:08 malletjo

hi @malletjo , thanks for the report. I will check this now

diegogub avatar Aug 30 '16 18:08 diegogub