go-playground / validator

:100:Go Struct and Field validation, including Cross Field, Cross Struct, Map, Slice and Array diving
MIT License
16.41k stars 1.3k forks source link

The filepath validator triggers a panic if the value is the path to an existing directory #1102

Open yansal opened 1 year ago

yansal commented 1 year ago

Package version eg. v9, v10:

v10.13.0

Issue, Question or Enhancement:

The filepath validator triggers a panic if the value is the path to an existing directory.

Code sample, to showcase or reproduce:

I have a failing test here https://github.com/yansal/validator/pull/1/files

The output of the test is here https://github.com/yansal/validator/actions/runs/4891503848/jobs/8732095225


panic: Bad field type string [recovered]
    panic: Bad field type string

goroutine 116 [running]:
testing.tRunner.func1.2({0x750340, 0xc000448920})
    /opt/hostedtoolcache/go/1.19.8/x64/src/testing/testing.go:1396 +0x372
testing.tRunner.func1()
    /opt/hostedtoolcache/go/1.19.8/x64/src/testing/testing.go:1399 +0x5f0
panic({0x750340, 0xc000448920})
    /opt/hostedtoolcache/go/1.19.8/x64/src/runtime/panic.go:890 +0x262
github.com/go-playground/validator/v10.isFilePath({0x824860?, 0xc000598900?})
    /home/runner/work/validator/validator/baked_in.go:1539 +0x3ae
github.com/go-playground/validator/v10.wrapFunc.func1({0xc000598900?, 0x750340?}, {0x824860, 0xc000598900})
    /home/runner/work/validator/validator/baked_in.go:42 +0x59
github.com/go-playground/validator/v10.(*validate).traverseField(0xc000598900, {0x8235f0, 0xc0000ba008}, {0x750340?, 0xc000448910?, 0x760c40?}, {0x750340?, 0xc000448910?, 0x760c40?}, {0xc000388cc0, ...}, ...)
    /home/runner/work/validator/validator/validator.go:454 +0x2ea8
github.com/go-playground/validator/v10.(*Validate).VarCtx(0xc0003b2700, {0x8235f0, 0xc0000ba008}, {0x750340?, 0xc000448910}, {0x7ae50f, 0x8})
    /home/runner/work/validator/validator/validator_instance.go:642 +0x465
github.com/go-playground/validator/v10.(*Validate).Var(0x7ae6bf?, {0x750340, 0xc000448910}, {0x7ae50f, 0x8})
    /home/runner/work/validator/validator/validator_instance.go:614 +0x8a
github.com/go-playground/validator/v10.TestFilePathValidation(0xc000382680)
    /home/runner/work/validator/validator/validator_test.go:5754 +0x2c5
testing.tRunner(0xc000382680, 0x7c9e30)
    /opt/hostedtoolcache/go/1.19.8/x64/src/testing/testing.go:1446 +0x217
created by testing.(*T).Run
    /opt/hostedtoolcache/go/1.19.8/x64/src/testing/testing.go:1493 +0x75e
FAIL    github.com/go-playground/validator/v10  0.085s