Skip to content
Snippets Groups Projects
Commit 2d771f5e authored by Loïc Correnson's avatar Loïc Correnson
Browse files

[server] escaped incorrect field name

parent 4187069a
No related branches found
No related tags found
No related merge requests found
...@@ -332,18 +332,21 @@ struct ...@@ -332,18 +332,21 @@ struct
if s.published then if s.published then
raise (Invalid_argument "Server.Data.Record: already published") raise (Invalid_argument "Server.Data.Record: already published")
let is_valid_field_name s name = let check_field_name s name =
if List.exists (fun f -> String.equal f.Package.fd_name name) s.fields then begin
raise (Invalid_argument ("Server.Data.Record: a field with name '" ^ name if List.exists (fun f -> f.Package.fd_name = name) s.fields then
^ "' already exists")) ; (let msg = Printf.sprintf "Server.Data.Record: duplicate field %S" name
if not (Str.string_match (Str.regexp "[a-zA-Z0-9 _-]+$") name 0) then in raise (Invalid_argument msg));
raise (Invalid_argument ("Server.Data.Record: field names must not be \ if not (Str.string_match (Str.regexp "[a-zA-Z0-9 _-]+$") name 0) then
exotic ('" ^ name ^ "')")) (let msg = Printf.sprintf
"Server.Data.Record: invalid characters for field %S" name in
raise (Invalid_argument msg));
end
let field (type a r) (s : r signature) let field (type a r) (s : r signature)
~name ~descr ?default (d : a data) : (r,a) field = ~name ~descr ?default (d : a data) : (r,a) field =
not_published s ; not_published s ;
is_valid_field_name s name ; check_field_name s name ;
let module D = (val d) in let module D = (val d) in
begin match default with begin match default with
| None -> () | None -> ()
...@@ -363,7 +366,7 @@ struct ...@@ -363,7 +366,7 @@ struct
let option (type a r) (s : r signature) let option (type a r) (s : r signature)
~name ~descr (d : a data) : (r,a option) field = ~name ~descr (d : a data) : (r,a option) field =
not_published s ; not_published s ;
is_valid_field_name s name ; check_field_name s name ;
let module D = (val d) in let module D = (val d) in
let field = Package.{ let field = Package.{
fd_name = name ; fd_name = name ;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment