Sanitizer
Data & parameter sanitizer
Every document that goes to the database needs to be sanitized first. This is to ensure that the document is properly saved according its schema definition.
If schema collection is provided (i.e: attributes
isn't empty), then on every create()
and update()
operation the body parameter is automatically sanitized:
According to its type:
boolean
,date
,datetime
,float
, andinteger
will automatically sanitized using its related sanitizer.According to its sanitizer definition below.
You can put one or more sanitizer on every attributes. Sanitizers put manually on attributes will override the one automatically provided according to its type.
Example:
From the example above:
username
will be trimmed from whitespace and accept any character except 1, 2, 3, 4 and 5name
will be trimed from whitespacegender
will be converted usingtoBoolean
sanitizerbirth_date
will be parsed usingYYYY-MM-DD
patternemail
will be sanitized usingnormalizeEmail
with custom options
If error occurs, or value doesn't match the provided pattern, value will be converted to null
All validator.js sanitizers are supported:
Sanitizer | Description (cited from validator.js) |
| Remove characters that appear in the blacklist |
| Replace |
| Replace HTML encoded entities with |
| Trim characters from the left-side |
| Canonicalizes an email address. More... |
| Trim characters from the right-side |
| Remove characters with a numerical value < 32 and 127, mostly control characters |
| Convert everything that isn't |
| Convert to a date. Format is one of moment.js supported format |
| Convert to a datetime.Format is one of moment.js supported format |
| Convert to a float |
| Convert to an integer |
| Trim characters (whitespace for |
| Remove characters that do not appear in the whitelist |
Last updated