processSetting

Function processing user input and validating for correctness.

The following validations are done:
If the setting is a disabledSetting, it will always skip this field.
If the setting has a settingPattern, it will validate the raw value (no matter what type) against this regex.
If the setting is a number, std.conv.to will be used to try to convert it to a double and then it will be cast to the type after checking min/max/step.
If the setting is a BitFlags!T every passed argument will be checked if it is contained inside the enum T or when submitted via JS only the one specified argument will get validated and inverted if starting with !
If the setting is an enum the value will be checked if it is contained inside the enum.
Additionally if the setting is a floating point number and there hasn't been a min/max setup but it is a rangeSetting, the number will be finite.
Integral numbers will always be checked if finite & if no range is given they will be clamped.

Attributes for strings:
emailSetting is validated using std.net.isemail.isEmail(CheckDns.no, EmailStatusCode.any)
urlSetting is validated using vibe.inet.url.URL
timeSetting is checked against pattern 00:00 + checking if 0 <= hour < 24 && 0 <= minute < 60
weekSetting is checked against pattern 0{4,6}-W00 + checking if 1 <= year <= 200000 && 1 <= week <= 52
monthSetting is checked against pattern 0{4,6}-00 + checking if 1 <= year <= 200000 && 1 <= month <= 12
datetimeLocalSetting is checked against pattern 0000-00-00T00:00 + passing into std.datetime.SysTime.fromISOExtString`
dateSetting is checked against pattern 0000-00-00 + checking the date using std.datetime.Date
colorSetting is checked against pattern #FFFFFF
Values using these attributes can be used without the need to validate the input.

@safe
bool
processSetting
(
string name
Config
)
(
HTTPServerRequest req
,
ref Config config
,
bool strict = false
,
bool post = true
)

Parameters

strict bool

if false, values will be fixed to conform to the input instead of discarding them. Currently only fixing numbers and string lengths and new lines in single line strings is implemented.

Return Value

Type: bool

a bit array where each bit represents an input and is set to 1 if valid

Meta