Commit d29ffa3a authored by Valentin Perrelle's avatar Valentin Perrelle
Browse files

[server] check fields declaration for name validity

parent 8d394a0c
......@@ -332,9 +332,18 @@ struct
if s.published then
raise (Invalid_argument "Server.Data.Record: already published")
let is_valid_field_name s name =
if List.exists (fun f -> String.equal f.Package.fd_name name) s.fields then
raise (Invalid_argument ("Server.Data.Record: a field with name '" ^ name
^ "' already exists")) ;
if not (Str.string_match (Str.regexp "[a-zA-Z0-9 _-]+$") name 0) then
raise (Invalid_argument ("Server.Data.Record: field names must not be \
exotic ('" ^ name ^ "')"))
let field (type a r) (s : r signature)
~name ~descr ?default (d : a data) : (r,a) field =
not_published s ;
is_valid_field_name s name ;
let module D = (val d) in
begin match default with
| None -> ()
......@@ -354,6 +363,7 @@ struct
let option (type a r) (s : r signature)
~name ~descr (d : a data) : (r,a option) field =
not_published s ;
is_valid_field_name s name ;
let module D = (val d) in
let field = Package.{
fd_name = name ;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment