Fix link to AFS Lore wiki
[openafs-wiki.git] / TWiki / VarENCODE.mdwn
1 <a name="VarENCODE"></a>
2
3 ### <a name="ENCODE{&quot;string&quot;} -- encodes a st"></a> ENCODE\{"string"\} -- encodes a string to HTML entities
4
5 - Encode "special" characters to HTML numeric entities. Encoded characters are:
6   - all non-printable ASCII characters below space, except newline (`"\n"`) and linefeed (`"\r"`)
7   - HTML special characters `"<"`, `">"`, `"&"`, single quote (`'`) and double quote (`"`)
8   - TWiki special characters `"%"`, `"["`, `"]"`, `"@"`, `"_"`, `"*"`, `"="` and `"|"`
9 - Syntax: `%ENCODE{"string"}%`
10 - Supported parameters: <table border="1" cellpadding="0" cellspacing="0">
11   <tr>
12     <th bgcolor="#99CCCC"><strong> Parameter: </strong></th>
13     <th bgcolor="#99CCCC"><strong> Description: </strong></th>
14     <th bgcolor="#99CCCC"><strong> Default: </strong></th>
15   </tr>
16   <tr>
17     <td><code>"string"</code></td>
18     <td> String to encode </td>
19     <td> required (can be empty) </td>
20   </tr>
21   <tr>
22     <td><code>type="safe"</code></td>
23     <td> Encode special characters into HTML entities to avoid XSS exploits: <code>"&lt;"</code>, <code>"&gt;"</code>, <code>"%"</code>, single quote (<code>'</code>) and double quote (<code>"</code>) </td>
24     <td><code>type="url"</code></td>
25   </tr>
26   <tr>
27     <td><code>type="entity"</code></td>
28     <td> Encode special characters into HTML entities, like a double quote into <code>&amp;#034;</code>. Does <strong>not</strong> encode <code>\n</code> or <code>\r</code>. </td>
29     <td><code>type="url"</code></td>
30   </tr>
31   <tr>
32     <td><code>type="html"</code></td>
33     <td> As <code>type="entity"</code> except it also encodes <code>\n</code> and <code>\r</code></td>
34     <td><code>type="url"</code></td>
35   </tr>
36   <tr>
37     <td><code>type="quotes"</code></td>
38     <td> Escape double quotes with backslashes (<code>\"</code>), does not change other characters </td>
39     <td><code>type="url"</code></td>
40   </tr>
41   <tr>
42     <td><code>type="url"</code></td>
43     <td> Encode special characters for URL parameter use, like a double quote into <code>%22</code></td>
44     <td> (this is the default) </td>
45   </tr>
46 </table>
47 - Example: `%ENCODE{"spaced name"}%` expands to `spaced%20name`
48 - **_%X% Notes:_**
49   - Values of HTML input fields must be entity encoded.%BR% Example: `<input type="text" name="address" value="%ENCODE{ "any text" type="entity" }%" />`
50   - Double quotes in strings must be escaped when passed into other TWiki variables.%BR% Example: `%SEARCH{ "%ENCODE{ "string with "quotes"" type="quotes" }%" noheader="on" }%`
51   - Use `type="entity"` or `type="safe"` to protect user input from URL parameters and external sources against cross-site scripting (XSS). `type="entity"` is more aggressive, but some TWiki applications might not work. `type="safe"` provides a safe middle ground.
52
53 - Related: [[URLPARAM|Main/VarURLPARAM]]