vweb: prohibit invalid parameter types in vweb app methods (#10631)
parent
f246d73d6e
commit
8c43d2450f
|
@ -7570,6 +7570,16 @@ fn (mut c Checker) verify_vweb_params_for_method(m ast.Fn) (bool, int, int) {
|
|||
// allow non custom routed methods, with 1:1 mapping
|
||||
return true, -1, margs
|
||||
}
|
||||
if m.params.len > 1 {
|
||||
for param in m.params[1..] {
|
||||
param_sym := c.table.get_final_type_symbol(param.typ)
|
||||
if !(param_sym.is_string() || param_sym.is_number() || param_sym.is_float()
|
||||
|| param_sym.kind == .bool) {
|
||||
c.error('invalid type `$param_sym.name` for parameter `$param.name` in vweb app method `$m.name`',
|
||||
param.pos)
|
||||
}
|
||||
}
|
||||
}
|
||||
mut route_attributes := 0
|
||||
for a in m.attrs {
|
||||
if a.name.starts_with('/') {
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
vlib/v/checker/tests/invalid_vweb_param_type.vv:8:24: error: invalid type `[]bool` for parameter `list` in vweb app method `index`
|
||||
6 |
|
||||
7 | ['/:list'; get]
|
||||
8 | fn (mut app App) index(list []bool) vweb.Result {
|
||||
| ~~~~
|
||||
9 | return app.text('')
|
||||
10 | }
|
|
@ -0,0 +1,12 @@
|
|||
import vweb
|
||||
|
||||
struct App {
|
||||
vweb.Context
|
||||
}
|
||||
|
||||
['/:list'; get]
|
||||
fn (mut app App) index(list []bool) vweb.Result {
|
||||
return app.text('')
|
||||
}
|
||||
|
||||
vweb.run(&App{}, 5000)
|
Loading…
Reference in New Issue