Deprecated legacy function. Use context-specific functions (e.g., encodeForHTML) instead.
Encodes data for a specific output context. This is a vital defense against Cross-Site Scripting (XSS) and injection attacks by ensuring characters are treated as data rather than executable code.
Lucee Function Reference
guardencode()
This Function is deprecated
Example
guardencode(string encodeFor,string string,[boolean canonicalize,[string dialect]]):string
Category
encode,xss,security,html,javascript,css,url,sql,xml,ldap,xpath
Arguments
The arguments for this function are set. You can not use other arguments except the following ones.
| Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
| encodeFor | string | Yes |
The target output context. Valid values: |
|
| string | string | Yes | The raw string to be encoded. | |
| canonicalize | boolean | No | false | If true, simplifies the input (resolving multiple/mixed encoding) before applying the new encoding. This prevents bypass attacks using double-encoding. |
| dialect | string | No |
Required only if encodeFor is 'sql'. Specifies the database syntax: * db2 * mysql_ansi * mysql * oracle |