Skip to content
isaiah edited this page Oct 21, 2015 · 2 revisions

String Escaping

Stacks provides access to the RapidWeaver string escaping API. You can specify a specific string escaping format whenever you template replace a string from an "input" control (a text box).

NB: The specific behavior of these encodings is controlled by Rapidweaver, not Stacks. For more info see the NSString+RMKit.h header file in the RMKit framework

String Escape Types

  • Javascript ( -encodeJS ) — Encoded for use inside a single-quoted string.
  • PHP ( -encodePHP ) — Encoded for use inside a single-quoted string.
  • HTML (-encodeHTML ) — Encoded for display on an HTML page (markup characters are hexadecimal encoded).
  • HTML Attribute ( -encodeHTMLAttribute ) — Encoded for use inside a double quoted HTML attribute (e.g. target="blank).
  • XML ( -encodeXML ) — Encoded for use inside XML strings.
  • Filename (-encodeFilename ) — Encoded for use as a file name on most filesystems.

Example

If this code is used inside a template:

<br>text (default):   %id=textInput%<br>
<br>text (JS):        %id=textInput -encodeJS%<br>
<br>text (PHP):       %id=textInput -encodePHP%<br>
<br>text (HTML):      %id=textInput -encodeHTML%<br>
<br>text (Attribute): %id=textInput -encodeHTMLAttribute%<br>
<br>text (XML):       %id=textInput -encodeXML%<br>
<br>text (Filename):  %id=textInput -encodeFile%<br>

This output will be produced:

<br>text (default):   this is a test " ' < > $<br>
<br>text (JS):        this is a test " \' < > $<br>
<br>text (PHP):       this is a test " \' < > $<br>
<br>text (HTML):      this is a test &#34; &#39; &#60; &#62; $<br>
<br>text (Attribute): this is a test &#34; &#39; &#60; &#62; $<br>
<br>text (XML):       this is a test &#34; &#39; &#60; &#62; $<br>
<br>text (Filename):  this-is-a-test-0022-0027-003C-003E-0024<br>

Clone this wiki locally