Class Index | File Index

Classes


Namespace Pot.Sanitizer


Defined in: <pot.js>.

Namespace Summary
Constructor Attributes Constructor Name and Description
 
Sanitizer.
Method Summary
Method Attributes Method Name and Description
<static>  
Pot.Sanitizer.escapeAppleScriptString(s)
Escape a string to use with AppleScript.
<static>  
Pot.Sanitizer.escapeFileName(fileName)
Escape the filename.
<static>  
Pot.Sanitizer.escapeHTML(text)
Escape the HTML string.
<static>  
Pot.Sanitizer.escapeRegExp(s)
Alias for rescape.
<static>  
Pot.Sanitizer.escapeSequence(text)
Convert a string that can be evaluated as JavaScript escape sequences.
<static>  
Pot.Sanitizer.escapeString(s)
Escape a string for basic code.
<static>  
Pot.Sanitizer.escapeXPathText(text)
Escape the XPath expression.
<static>  
Pot.Sanitizer.rescape(s)
Escape RegExp patterns.
<static>  
Pot.Sanitizer.unescapeHTML(text)
Unescape the HTML string.
<static>  
Pot.Sanitizer.unescapeSequence(text)
Revert the converted string as JavaScript escape sequences.
<static>  
Pot.Sanitizer.unescapeString(s)
Unescape a string for basic code.
Namespace Detail
Pot.Sanitizer
Sanitizer. This object escape the string or filename, and expressions, these will be sanitized safely.
Method Detail
<static> {Function} Pot.Sanitizer.escapeAppleScriptString(s)
Escape a string to use with AppleScript.
  var file = escapeAppleScriptString('ヾ("ゝω・")ノ"');
  var command = [
    'tell application "Finder"',
    '  get exists of file "' + file + '" of desktop',
    'end tell'
  ].join('\n');
  debug(command);
  // @results
  //   tell application "Finder"
  //     get exists of file "ヾ(\"ゝω・\")ノ\"" of desktop
  //   end tell
Parameters:
{String} s
A target string.
Returns:
{String} The escaped string.

<static> {Function} Pot.Sanitizer.escapeFileName(fileName)
Escape the filename. Escapes to be a safe filename for each OS. {@link http://mxr.mozilla.org/mozilla/source/toolkit/ content/contentAreaUtils.js#818 }
  var fileName = '゚・*:.。..。.:*・゚(file)゚・*:.。. .。.:*・゚・*';
  var escaped = escapeFileName(fileName);
  debug(escaped);
  // @results '゚・ .。..。. ・゚(file)゚・ .。. .。. ・゚・ ' (on Windows)
Parameters:
{String} fileName
A target filename.
Returns:
{String} A validated filename.

<static> {Function} Pot.Sanitizer.escapeHTML(text)
Escape the HTML string. HTML entities will be escaped.
  var string = '(>_<)/"< Hello World!';
  var result = escapeHTML(string);
  debug(result);
  // @results '(&gt;_&lt;)/&quot;&lt; Hello World!'
  //
  // for JSDoc: (@results)
  // '(&amp;gt;_&amp;lt;)/&amp;quot;&amp;lt; Hello World!'
Parameters:
{String} text
The target string.
Returns:
{String} The escaped string.

<static> {Function} Pot.Sanitizer.escapeRegExp(s)
Alias for rescape.
Parameters:
{String} s
A target string.
Returns:
{String} The escaped string.
See:
Pot.Sanitizer.rescape

<static> {Function} Pot.Sanitizer.escapeSequence(text)
Convert a string that can be evaluated as JavaScript escape sequences. This function converts more characters than JSON. (i.e. enabled as JSON)
  var string = 'ほげabc ("w")';
  var result = escapeSequence(string);
  debug(result);
  // @results  '\u307b\u3052abc\u0020(\"\uff57\")'
Parameters:
{String} text
A target string.
Returns:
{String} The escaped string.

<static> {Function} Pot.Sanitizer.escapeString(s)
Escape a string for basic code.
  var result = 'id="' + escapeString('foo"bar"') + '"';
  debug(result);
  // @results id="foo\"bar\""
Parameters:
{String} s
A target string.
Returns:
{String} The escaped string.

<static> {Function} Pot.Sanitizer.escapeXPathText(text)
Escape the XPath expression.
  var text = '"] | /foo/bar/baz | .["';
  var expr = '//*[@class=' + escapeXPathText(text) + ']';
  // e.g. var element = $x(expr, document, true);
  debug(expr);
  // @results //*[@class=concat('"',"] | /foo/bar/baz | .[",'"')]
  var text = 'hoge-class';
  var expr = '//*[@class=' + escapeXPathText(text) + ']';
  debug(expr);
  // @results //*[@class="hoge-class"]
Parameters:
{String} text
A string to be escaped.
Returns:
{String} The escaped string.

<static> {Function} Pot.Sanitizer.rescape(s)
Escape RegExp patterns.
  var pattern = 'ムキュ*・゚・*..:*・(≧∀≦)゚・*:.。.*゚:!!';
  var regex = new RegExp('^(' + rescape(pattern) + ')$', 'g');
  debug(regex.toString());
  // @results /^(ムキュ\*・゚・\*\.\.:\*・\(≧∀≦\)゚・\*:\.。\.\*゚:!!)$/g
Parameters:
{String} s
A target string.
Returns:
{String} The escaped string.

<static> {Function} Pot.Sanitizer.unescapeHTML(text)
Unescape the HTML string. HTML entities will be unescaped.
  var string = '(&gt;_&lt;)/&quot;&lt; Hello World!';
  // for JSDoc: (string)
  // '(&amp;gt;_&amp;lt;)/&amp;quot;&amp;lt; Hello World!'
  //
  var result = unescapeHTML(string);
  debug(result);
  // @results '(>_<)/"< Hello World!'
Parameters:
{String} text
The target string.
Returns:
{String} The unescaped string.

<static> {Function} Pot.Sanitizer.unescapeSequence(text)
Revert the converted string as JavaScript escape sequences.
  var string = '\\u307b\\u3052abc\\u0020(\\"\\uff57\\")';
  var result = unescapeSequence(string);
  debug(result);
  // @results  'ほげabc ("w")'
Parameters:
{String} text
A target string.
Returns:
{String} The unescaped string.

<static> {Function} Pot.Sanitizer.unescapeString(s)
Unescape a string for basic code.
  var result = unescapeString('foo=\\"bar\\"');
  debug(result);
  // @results foo="bar"
Parameters:
{String} s
A target string.
Returns:
{String} The unescaped string.

Documentation generated by JsDoc Toolkit 2.4.0 on Fri Sep 21 2012 19:32:22 GMT+0900 (JST)