%META:TOPICINFO{author="TWikiContributor" date="1352708512" format="1.1" version="1"}% %META:TOPICPARENT{name="TWikiVariables"}% #VarENTITY ---+++ ENTITY{string} -- encode a string to HTML entities * Encode "special" characters to HTML entities. Useful to encode text properly for HTML input fields. * Encoded characters: * all non-printable ASCII characters below space, including newline (="\n"=) and linefeed (="\r"=) * Space * HTML special characters ="<"=, =">"=, ="&"=, single quote (='=) and double quote (="=) * TWiki special characters ="%"=, ="["=, ="]"=, ="@"=, ="_"=, ="*"=, ="="= and ="|"= * Syntax: =%ENTITY{string}%= * Example: =%ENTITY{text with "quotes" and%BR%newline}%= expands to =text&#32;with&#32;&#34;quotes&#34;&#32;and&#10;newline= * __Notes:__ * To protect against [[http://en.wikipedia.org/wiki/Cross-site_scripting][cross-site scripting]] (XSS), __always__ entity encode text intended for HTML input fields. This is especially true if text is received dynamically via URLPARAM or the like. %BR% Example: =<input type="text" name="address" value="%ENTITY{any text}%" />= * =%ENTITY{string}%= is roughly equivalent to =%ENCODE{ "string" type="html" }%=, but the latter cannot handle strings that have double quotes embedded in it. * Category: DevelopmentVariables, FormattingAndRenderingVariables, ExportAndPublishingVariables * Related: [[%IF{"'%INCLUDINGTOPIC%'='TWikiVariables'" then="#"}%VarENCODE][ENCODE]], [[%IF{"'%INCLUDINGTOPIC%'='TWikiVariables'" then="#"}%VarFORMFIELD][FORMFIELD]], [[%IF{"'%INCLUDINGTOPIC%'='TWikiVariables'" then="#"}%VarQUERYPARAMS][QUERYPARAMS]], [[%IF{"'%INCLUDINGTOPIC%'='TWikiVariables'" then="#"}%VarURLPARAM][URLPARAM]]