@@ -129,6 +129,18 @@ func TestOapiRequestValidator(t *testing.T) {
129129 called = true
130130 return nil
131131 })
132+ // add a Handler for an encoded path parameter
133+ // this needs to be installed before calling the first doGet
134+ // because of echo internals (maxParam)
135+ e .GET ("/resource/minlength/:encoded" , func (c echo.Context ) error {
136+ called = true
137+ return c .NoContent (http .StatusNoContent )
138+ })
139+ e .GET ("/resource/pattern/:encoded" , func (c echo.Context ) error {
140+ called = true
141+ return c .NoContent (http .StatusNoContent )
142+ })
143+
132144 // Let's send the request to the wrong server, this should return 404
133145 {
134146 rec := doGet (t , e , "http://not.deepmap.ai/resource" )
@@ -231,6 +243,42 @@ func TestOapiRequestValidator(t *testing.T) {
231243 assert .False (t , called , "Handler should not have been called" )
232244 called = false
233245 }
246+
247+ // Let's send a request with an encoded parameter
248+ // It should pass validation
249+ {
250+ rec := doGet (t , e , "http://deepmap.ai/resource/minlength/%2B" )
251+ assert .Equal (t , http .StatusNoContent , rec .Code )
252+ assert .True (t , called , "Handler should have been called" )
253+ called = false
254+ }
255+
256+ // Let's send a request with an unencoded parameter
257+ // It should pass as well
258+ {
259+ rec := doGet (t , e , "http://deepmap.ai/resource/minlength/+" )
260+ assert .Equal (t , http .StatusNoContent , rec .Code )
261+ assert .True (t , called , "Handler should have been called" )
262+ called = false
263+ }
264+
265+ // Let's send a request with an encoded parameter
266+ // It should pass validation
267+ {
268+ rec := doGet (t , e , "http://deepmap.ai/resource/pattern/%2B1234" )
269+ assert .Equal (t , http .StatusNoContent , rec .Code )
270+ assert .True (t , called , "Handler should have been called" )
271+ called = false
272+ }
273+
274+ // Let's send a request with an unencoded parameter
275+ // It should pass as well
276+ {
277+ rec := doGet (t , e , "http://deepmap.ai/resource/pattern/+1234" )
278+ assert .Equal (t , http .StatusNoContent , rec .Code )
279+ assert .True (t , called , "Handler should have been called" )
280+ called = false
281+ }
234282}
235283
236284func TestOapiRequestValidatorWithOptionsMultiError (t * testing.T ) {
0 commit comments