govalidator icon indicating copy to clipboard operation
govalidator copied to clipboard

suspicious regexp.Compile usage in utils.go

Open quasilyte opened this issue 5 years ago • 1 comments

./github.com/asaskevich/govalidator/utils.go:156:21: regexpMust: for const patterns like `[ &_=+:]`, use regexp.MustCompile
./github.com/asaskevich/govalidator/utils.go:160:16: regexpMust: for const patterns like `[^[:alnum:]-.]`, use regexp.MustCompile

https://github.com/asaskevich/govalidator/blob/f9ffefc3facfbe0caee3fea233cbb6e8208f4541/utils.go#L156-L159

Since the pattern is constant, one might want to use regexp.MustCompile there and avoid the awkward err == nil branch. If there is an error in pattern, it should be fixed inside a source code.

As a side note, regexp compilation should probably be moved to outside of the function if it's called multiple times. Compilation is a slow operation for regexp pacakge.

quasilyte avatar Jan 26 '19 10:01 quasilyte

Hello guys! I forked this package cause owner disappeared. Hope, he will be back, but it would be easier to merge these changes back if he is back Link to my repo: create issue there and we'll discuss it.

sergeyglazyrindev avatar Oct 17 '21 21:10 sergeyglazyrindev