brianvoe / gofakeit

Random fake data generator written in go
MIT License
4.56k stars 264 forks source link

Invalid tag causes infinte loop #349

Closed KevinJoiner closed 8 months ago

KevinJoiner commented 8 months ago

When using struct tags that are missing closing brackets, generation hangs indefinitely. Though this is an invalid tag, it would be helpful to return an error or skip the malformed field.

https://go.dev/play/p/oqXL9XRwykg

package main

import (
    "fmt"

    "github.com/brianvoe/gofakeit/v7"
)

// Create structs with random injected data
type Foo struct {
    RandStr string `fake:"{randomstring:[hello,world}"` // missing closing `]`
       // RandStr string `fake:"{randomstring:[hello,world]}"`
}

func main() {
    var f Foo
    err := gofakeit.Struct(&f)
    if err != nil {
        panic(err)
    }

    fmt.Println(f.RandStr) 
    fmt.Println("finished")
}
brianvoe commented 8 months ago

I actually agree with that!

Let me see if i can add a check for it easily

brianvoe commented 8 months ago

Fixed v7.0.1