webmcp
view framework/env/param/_get_parser.lua @ 3:795b764629ca
Version 1.0.3
Important bugfix related to internal forwards (Bug was introduced by the restriction of views with underscore prefix in Version 1.0.2)
Important bugfix related to internal forwards (Bug was introduced by the restriction of views with underscore prefix in Version 1.0.2)
author | jbe |
---|---|
date | Thu Dec 10 12:00:00 2009 +0100 (2009-12-10) |
parents | 9fdfb27f8e67 |
children |
line source
1 function param._get_parser(format_info, param_type)
2 if format_info == nil or format_info == "" then
3 return function(str)
4 return param_type:load(str)
5 end
6 else
7 local format_options = {}
8 local format_type, rest = string.match(
9 format_info,
10 "^([A-Za-z][A-Za-z0-9_]*)(.*)$"
11 )
12 if format_type then
13 rest = string.gsub(rest, "\\\\", "\\e")
14 rest = string.gsub(rest, "\\'", "\\q")
15 if
16 string.find(rest, "\\$") or
17 string.find(rest, "\\[^eq]")
18 then
19 format_type = nil
20 else
21 while rest ~= "" do
22 local key, value, new_rest
23 key, value, new_rest = string.match(
24 rest,
25 "^-([A-Za-z][A-Za-z0-9_]*)-'([^']*)'(.*)$"
26 )
27 if value then
28 value = string.gsub(value, "\\q", "'")
29 value = string.gsub(value, "\\e", "\\")
30 format_options[key] = value
31 else
32 key, value, new_rest = string.match(
33 rest,
34 "^-([A-Za-z][A-Za-z0-9_]*)-([^-]*)(.*)$"
35 )
36 if value then
37 if string.find(value, "^[0-9.Ee+-]+$") then
38 local num = tonumber(value)
39 if not num then
40 format_type = nil
41 break
42 end
43 format_options[key] = num
44 elseif value == "t" then
45 format_options[key] = true
46 elseif value == "f" then
47 format_options[key] = false
48 else
49 format_type = nil
50 break
51 end
52 else
53 format_type = nil
54 break
55 end
56 end
57 rest = new_rest
58 end
59 end
60 end
61 if not format_type then
62 error("Illegal format string in GET/POST parameters found.")
63 end
64 local parse_func = parse[format_type]
65 if not parse_func then
66 error("Unknown format identifier in GET/POST parameters encountered.")
67 end
68 return function(str)
69 return parse_func(str, param_type, format_options)
70 end
71 end
72 end