Validator: Undefined validation function 'html_encoded'

Created on 8 Aug 2018  路  6Comments  路  Source: go-playground/validator

Package version eg. v8, v9:

"gopkg.in/go-playground/validator.v9"

Issue, Question or Enhancement:

Undefined validation function 'html_encoded'

Code sample, to showcase or reproduce:

```go in struct

Post_content_text string xorm:"text 'post_content_text'" form:"post_content_text" validate:"required,html_encoded"
```

when i run i've got this error in console..

Undefined validation function 'html_encoded' on field 'Post_content_summary' goroutine 10 [running]:\ngithub.com/labstack/echo/middleware.RecoverWithConfig.func1.1.1(0xf2b570, 0x1000, 0x0, 0xfc78a0, 0xc0422ce150)\n\tF:/go-workspace/src/github.com/labstack/echo/middleware/recover.go:71 +0xfe\npanic(0xd184a0, 0xc0423de270)\n\tF:/Go/src/runtime/panic.go:502 +0x237\ngopkg.in/go-playground/validator%2ev9.(Validate).parseFieldTagsRecursive(0xc04206a9c0, 0xdb61e1, 0x1d, 0xdb616d, 0x14, 0xdb61ea, 0x0, 0xd18400, 0xdb6183, 0x7c)\n\tF:/go-workspace/src/gopkg.in/go-playground/validator.v9/cache.go:304 +0x1036\ngopkg.in/go-playground/validator%2ev9.(Validate).extractStructCache(0xc04206a9c0, 0xe56340, 0xc042428090, 0x99, 0xcb9e41, 0x14, 0x0)\n\tF:/go-workspace/src/gopkg.in/go-playground/validator.v9/cache.go:156 +0x46b\ngopkg.in/go-playground/validator%2ev9.(validate).validateStruct(0xc042426120, 0xfbf4c0, 0xc042080058, 0xe56340, 0xc042428090, 0x99, 0xe56340, 0xc042428090, 0x99, 0xfc6b40, ...)\n\tF:/go-workspace/src/gopkg.in/go-playground/validator.v9/validator.go:37 +0xae3\ngopkg.in/go-playground/validator%2ev9.(Validate).StructCtx(0xc04206a9c0, 0xfbf4c0, 0xc042080058, 0xe56340, 0xc042428090, 0x0, 0xc04205e400)\n\tF:/go-workspace/src/gopkg.in/go-playground/validator.v9/validator_instance.go:275 +0x327\ngopkg.in/go-playground/validator%2ev9.(Validate).Struct(0xc04206a9c0, 0xe56340, 0xc042428090, 0xc0420676d0, 0x807c5a)\n\tF:/go-workspace/src/gopkg.in/go-playground/validator.v9/validator_instance.go:248 +0x5e\nmain.(CustomValidator).Validate(0xc042004178, 0xe56340, 0xc042428090, 0xc042428090, 0xc042428090)\n\tF:/go-workspace/src/qubicle-api-v3_0/main.go:90 +0x49\ngithub.com/labstack/echo.(context).Validate(0xc0422ce150, 0xe56340, 0xc042428090, 0xc042428090, 0x0)\n\tF:/go-workspace/src/github.com/labstack/echo/context.go:381 +0x62\nqubicle-api-v3_0/services.CMS_PostCreate_post.func1(0xfc78a0, 0xc0422ce150, 0x4, 0xd73fa0)\n\tF:/go-workspace/src/qubicle-api-v3_0/services/cms_service.go:3190 +0x117c\ngithub.com/labstack/echo/middleware.JWTWithConfig.func2.1(0xfc78a0, 0xc0422ce150, 0xed22b9, 0x1b)\n\tF:/go-workspace/src/github.com/labstack/echo/middleware/jwt.go:156 +0x241\ngithub.com/labstack/echo.(Echo).Add.func1(0xfc78a0, 0xc0422ce150, 0x1b, 0xeba3c0)\n\tF:/go-workspace/src/github.com/labstack/echo/echo.go:480 +0x8e\ngithub.com/labstack/echo/middleware.CORSWithConfig.func1.1(0xfc78a0, 0xc0422ce150, 0xf2b570, 0x1000)\n\tF:/go-workspace/src/github.com/labstack/echo/middleware/cors.go:113 +0x32b\ngithub.com/labstack/echo/middleware.RecoverWithConfig.func1.1(0xfc78a0, 0xc0422ce150, 0x0, 0x0)\n\tF:/go-workspace/src/github.com/labstack/echo/middleware/recover.go:78 +0xde\ngithub.com/labstack/echo/middleware.LoggerWithConfig.func2.1(0xfc78a0, 0xc0422ce150, 0x0, 0x0)\n\tF:/go-workspace/src/github.com/labstack/echo/middleware/logger.go:116 +0x11e\ngithub.com/labstack/echo.(Echo).ServeHTTP(0xc0422fd040, 0xfbe900, 0xc042404000, 0xc0421b3100)\n\tF:/go-workspace/src/github.com/labstack/echo/echo.go:592 +0x257\nnet/http.serverHandler.ServeHTTP(0xc0422e8dd0, 0xfbe900, 0xc042404000, 0xc0421b3100)\n\tF:/Go/src/net/http/server.go:2694 +0xc3\nnet/http.(conn).serve(0xc0422ed9a0, 0xfbf480, 0xc042243a40)\n\tF:/Go/src/net/http/server.go:1830 +0x658\ncreated by net/http.(Server).Serve\n\tF:/Go/src/net/http/server.go:2795 +0x282\n\ngoroutine 1 [IO wait]:\ninternal/poll.runtime_pollWait(0x37d0dd0, 0x72, 0xfb9120)\n\tF:/Go/src/runtime/netpoll.go:173 +0x5e\ninternal/poll.(pollDesc).wait(0xc04231fa88, 0x72, 0x13dc500, 0x0, 0x0)\n\tF:/Go/src/internal/poll/fd_poll_runtime.go:85 +0xa2\ninternal/poll.(ioSrv).ExecIO(0x142ef18, 0xc04231f8d8, 0xc0423ad3a0, 0x1, 0x0, 0x1bc)\n\tF:/Go/src/internal/poll/fd_windows.go:223 +0x13a\ninternal/poll.(FD).acceptOne(0xc04231f8c0, 0x1bc, 0xc042354380, 0x2, 0x2, 0xc04231f8d8, 0x477d49, 0xc042263940, 0x4107ef, 0x10)\n\tF:/Go/src/internal/poll/fd_windows.go:793 +0xae\ninternal/poll.(FD).Accept(0xc04231f8c0, 0xc0423fc420, 0x0, 0x0, 0x0, 0x0, 0xc000000000, 0x0, 0x0, 0x0, ...)\n\tF:/Go/src/internal/poll/fd_windows.go:827 +0x142\nnet.(netFD).accept(0xc04231f8c0, 0x40ff01, 0xc042263ad8, 0x42a8ab)\n\tF:/Go/src/net/fd_windows.go:192 +0x86\nnet.(*TCPListener).accept(0xc042004440, 0x\n"}

can somebody help me ?

Most helpful comment

Doesn't look like this is the issue the OP is facing, but in case somebody searches and lands here it might save them a bit of head scratching. You can get an 'Undefined validation function' panic if there's whitespace in the tag e.g. validate:"required, foo".

All 6 comments

Hey @youcandoit95

can you confirm you have the latest version of the code, the validation was added recently?

Doesn't look like this is the issue the OP is facing, but in case somebody searches and lands here it might save them a bit of head scratching. You can get an 'Undefined validation function' panic if there's whitespace in the tag e.g. validate:"required, foo".

@youcandoit95 did updating help?

closing due to no response.

I'm encountering the same problem.

Here is what I guess would be the problem

  • I'm updating my gin custom binding validator in init() method
  • in the program main function, I've var validator *validate.Validator, and from there I call
    validate.RegisterValidation(tag, customTag).
    However, my custom tag is not being recognized.

And I'm using gin's binding.

I've fixed it.
You have to, which was clearly written in the validator.v8 -> v9 upgrade, to register your custom functions in func (v *defaultValidator) lazyinit() func.

Was this page helpful?
0 / 5 - 0 ratings