1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
|
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Module: Escape</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
<script type="text/javascript">
// <![CDATA[
function popupCode( url ) {
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
}
function toggleCode( id ) {
if ( document.getElementById )
elem = document.getElementById( id );
else if ( document.all )
elem = eval( "document.all." + id );
else
return false;
elemStyle = elem.style;
if ( elemStyle.display != "block" ) {
elemStyle.display = "block"
} else {
elemStyle.display = "none"
}
return true;
}
// Make codeblocks hidden by default
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
// ]]>
</script>
</head>
<body>
<div id="classHeader">
<table class="header-table">
<tr class="top-aligned-row">
<td><strong>Module</strong></td>
<td class="class-name-in-header">Escape</td>
</tr>
<tr class="top-aligned-row">
<td><strong>In:</strong></td>
<td>
<a href="../files/escape_rb.html">
escape.rb
</a>
<br />
</td>
</tr>
</table>
</div>
<!-- banner header -->
<div id="bodyContent">
<div id="contextContent">
<div id="description">
<p>
<a href="Escape.html">Escape</a> module provides several escape functions.
</p>
<ul>
<li>URI
</li>
<li>HTML
</li>
<li>shell command
</li>
</ul>
</div>
</div>
<div id="method-list">
<h3 class="section-bar">Methods</h3>
<div class="name-list">
<a href="#M000028">html_attr_value</a>
<a href="#M000026">html_form</a>
<a href="#M000027">html_text</a>
<a href="#M000022">shell_command</a>
<a href="#M000023">shell_single_word</a>
<a href="#M000025">uri_path</a>
<a href="#M000024">uri_segment</a>
</div>
</div>
</div>
<!-- if includes -->
<div id="section">
<div id="class-list">
<h3 class="section-bar">Classes and Modules</h3>
Class <a href="Escape/HTMLAttrValue.html" class="link">Escape::HTMLAttrValue</a><br />
Class <a href="Escape/HTMLEscaped.html" class="link">Escape::HTMLEscaped</a><br />
Class <a href="Escape/PercentEncoded.html" class="link">Escape::PercentEncoded</a><br />
Class <a href="Escape/ShellEscaped.html" class="link">Escape::ShellEscaped</a><br />
Class <a href="Escape/StringWrapper.html" class="link">Escape::StringWrapper</a><br />
</div>
<!-- if method_list -->
<div id="methods">
<h3 class="section-bar">Public Instance methods</h3>
<div id="method-M000028" class="method-detail">
<a name="M000028"></a>
<div class="method-heading">
<a href="Escape.src/M000028.html" target="Code" class="method-signature"
onclick="popupCode('Escape.src/M000028.html');return false;">
<span class="method-name">html_attr_value</span><span class="method-args">(str)</span>
</a>
</div>
<div class="method-description">
<p>
<a href="Escape.html#M000028">Escape.html_attr_value</a> encodes a string
as a double-quoted HTML attribute using character references. It returns an
instance of <a href="Escape/HTMLAttrValue.html">HTMLAttrValue</a>.
</p>
<pre>
Escape.html_attr_value("abc") #=> #<Escape::HTMLAttrValue: "abc">
Escape.html_attr_value("a&b") #=> #<Escape::HTMLAttrValue: "a&amp;b">
Escape.html_attr_value("ab&<>\"c") #=> #<Escape::HTMLAttrValue: "ab&amp;&lt;&gt;&quot;c">
Escape.html_attr_value("a'c") #=> #<Escape::HTMLAttrValue: "a'c">
</pre>
<p>
It escapes 4 characters:
</p>
<ul>
<li>’&’ to ’&amp;’
</li>
<li>’<’ to ’&lt;’
</li>
<li>’>’ to ’&gt;’
</li>
<li>’"’ to ’&quot;’
</li>
</ul>
</div>
</div>
<div id="method-M000026" class="method-detail">
<a name="M000026"></a>
<div class="method-heading">
<a href="Escape.src/M000026.html" target="Code" class="method-signature"
onclick="popupCode('Escape.src/M000026.html');return false;">
<span class="method-name">html_form</span><span class="method-args">(pairs, sep='&')</span>
</a>
</div>
<div class="method-description">
<p>
<a href="Escape.html#M000026">Escape.html_form</a> composes HTML form
key-value pairs as a x-www-form-urlencoded encoded string. It returns an
instance of <a href="Escape/PercentEncoded.html">PercentEncoded</a>.
</p>
<p>
<a href="Escape.html#M000026">Escape.html_form</a> takes an array of pair
of strings or an hash from string to string.
</p>
<pre>
Escape.html_form([["a","b"], ["c","d"]]) #=> #<Escape::PercentEncoded: a=b&c=d>
Escape.html_form({"a"=>"b", "c"=>"d"}) #=> #<Escape::PercentEncoded: a=b&c=d>
</pre>
<p>
In the array form, it is possible to use same key more than once. (It is
required for a HTML form which contains checkboxes and select element with
multiple attribute.)
</p>
<pre>
Escape.html_form([["k","1"], ["k","2"]]) #=> #<Escape::PercentEncoded: k=1&k=2>
</pre>
<p>
If the strings contains characters which must be escaped in
x-www-form-urlencoded, they are escaped using %-encoding.
</p>
<pre>
Escape.html_form([["k=","&;="]]) #=> #<Escape::PercentEncoded: k%3D=%26%3B%3D>
</pre>
<p>
The separator can be specified by the optional second argument.
</p>
<pre>
Escape.html_form([["a","b"], ["c","d"]], ";") #=> #<Escape::PercentEncoded: a=b;c=d>
</pre>
<p>
See HTML 4.01 for details.
</p>
</div>
</div>
<div id="method-M000027" class="method-detail">
<a name="M000027"></a>
<div class="method-heading">
<a href="Escape.src/M000027.html" target="Code" class="method-signature"
onclick="popupCode('Escape.src/M000027.html');return false;">
<span class="method-name">html_text</span><span class="method-args">(str)</span>
</a>
</div>
<div class="method-description">
<p>
<a href="Escape.html#M000027">Escape.html_text</a> escapes a string
appropriate for HTML text using character references. It returns an
instance of <a href="Escape/HTMLEscaped.html">HTMLEscaped</a>.
</p>
<p>
It escapes 3 characters:
</p>
<ul>
<li>’&’ to ’&amp;’
</li>
<li>’<’ to ’&lt;’
</li>
<li>’>’ to ’&gt;’
</li>
</ul>
<pre>
Escape.html_text("abc") #=> #<Escape::HTMLEscaped: abc>
Escape.html_text("a & b < c > d") #=> #<Escape::HTMLEscaped: a &amp; b &lt; c &gt; d>
</pre>
<p>
This function is not appropriate for escaping HTML element attribute
because quotes are not escaped.
</p>
</div>
</div>
<div id="method-M000022" class="method-detail">
<a name="M000022"></a>
<div class="method-heading">
<a href="Escape.src/M000022.html" target="Code" class="method-signature"
onclick="popupCode('Escape.src/M000022.html');return false;">
<span class="method-name">shell_command</span><span class="method-args">(command)</span>
</a>
</div>
<div class="method-description">
<p>
<a href="Escape.html#M000022">Escape.shell_command</a> composes a sequence
of words to a single shell command line. All shell meta characters are
quoted and the words are concatenated with interleaving space. It returns
an instance of <a href="Escape/ShellEscaped.html">ShellEscaped</a>.
</p>
<pre>
Escape.shell_command(["ls", "/"]) #=> #<Escape::ShellEscaped: ls />
Escape.shell_command(["echo", "*"]) #=> #<Escape::ShellEscaped: echo '*'>
</pre>
<p>
Note that system(*command) and system(<a
href="Escape.html#M000022">Escape.shell_command(command)</a>) is roughly
same. There are two exception as follows.
</p>
<ul>
<li>The first is that the later may invokes /bin/sh.
</li>
<li>The second is an interpretation of an array with only one element: the
element is parsed by the shell with the former but it is recognized as
single word with the later. For example, system(*["echo foo"])
invokes echo command with an argument "foo". But system(<a
href="Escape.html#M000022">Escape.shell_command</a>(["echo
foo"])) invokes "echo foo" command without arguments (and it
probably fails).
</li>
</ul>
</div>
</div>
<div id="method-M000023" class="method-detail">
<a name="M000023"></a>
<div class="method-heading">
<a href="Escape.src/M000023.html" target="Code" class="method-signature"
onclick="popupCode('Escape.src/M000023.html');return false;">
<span class="method-name">shell_single_word</span><span class="method-args">(str)</span>
</a>
</div>
<div class="method-description">
<p>
<a href="Escape.html#M000023">Escape.shell_single_word</a> quotes shell
meta characters. It returns an instance of <a
href="Escape/ShellEscaped.html">ShellEscaped</a>.
</p>
<p>
The result string is always single shell word, even if the argument is
"". <a
href="Escape.html#M000023">Escape.shell_single_word</a>("")
returns #<<a href="Escape/ShellEscaped.html">Escape::ShellEscaped</a>:
’’>.
</p>
<pre>
Escape.shell_single_word("") #=> #<Escape::ShellEscaped: ''>
Escape.shell_single_word("foo") #=> #<Escape::ShellEscaped: foo>
Escape.shell_single_word("*") #=> #<Escape::ShellEscaped: '*'>
</pre>
</div>
</div>
<div id="method-M000025" class="method-detail">
<a name="M000025"></a>
<div class="method-heading">
<a href="Escape.src/M000025.html" target="Code" class="method-signature"
onclick="popupCode('Escape.src/M000025.html');return false;">
<span class="method-name">uri_path</span><span class="method-args">(str)</span>
</a>
</div>
<div class="method-description">
<p>
<a href="Escape.html#M000025">Escape.uri_path</a> escapes URI path using
percent-encoding. The given path should be a sequence of (non-escaped)
segments separated by "/". The segments cannot contains
"/". It returns an instance of <a
href="Escape/PercentEncoded.html">PercentEncoded</a>.
</p>
<pre>
Escape.uri_path("a/b/c") #=> #<Escape::PercentEncoded: a/b/c>
Escape.uri_path("a?b/c?d/e?f") #=> #<Escape::PercentEncoded: a%3Fb/c%3Fd/e%3Ff>
</pre>
<p>
The path is the part after authority before query in URI, as follows.
</p>
<pre>
scheme://authority/path#fragment
</pre>
<p>
See RFC 3986 for details of URI.
</p>
<p>
Note that this function is not appropriate to convert OS path to URI.
</p>
</div>
</div>
<div id="method-M000024" class="method-detail">
<a name="M000024"></a>
<div class="method-heading">
<a href="Escape.src/M000024.html" target="Code" class="method-signature"
onclick="popupCode('Escape.src/M000024.html');return false;">
<span class="method-name">uri_segment</span><span class="method-args">(str)</span>
</a>
</div>
<div class="method-description">
<p>
<a href="Escape.html#M000024">Escape.uri_segment</a> escapes URI segment
using percent-encoding. It returns an instance of <a
href="Escape/PercentEncoded.html">PercentEncoded</a>.
</p>
<pre>
Escape.uri_segment("a/b") #=> #<Escape::PercentEncoded: a%2Fb>
</pre>
<p>
The segment is "/"-splitted element after authority before query
in URI, as follows.
</p>
<pre>
scheme://authority/segment1/segment2/.../segmentN?query#fragment
</pre>
<p>
See RFC 3986 for details of URI.
</p>
</div>
</div>
</div>
</div>
<div id="validator-badges">
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>
</body>
</html>
|