narf 0.5.1 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/ChangeLog +44 -0
  2. data/README +6 -2
  3. data/README~ +124 -0
  4. data/build.rb +3 -2
  5. data/build.rb~ +1 -1
  6. data/doc/apache_cgi.txt +1 -5
  7. data/doc/apache_cgi.txt~ +17 -0
  8. data/doc/fastcgi.txt +1 -1
  9. data/doc/fastcgi.txt~ +19 -0
  10. data/doc/rdoc/classes/Web.html +9 -6
  11. data/doc/rdoc/classes/Web.src/M000002.html +1 -1
  12. data/doc/rdoc/classes/Web.src/M000003.html +1 -1
  13. data/doc/rdoc/classes/Web.src/M000004.html +1 -1
  14. data/doc/rdoc/classes/Web.src/M000005.html +1 -1
  15. data/doc/rdoc/classes/Web.src/M000006.html +1 -1
  16. data/doc/rdoc/classes/Web.src/M000007.html +1 -1
  17. data/doc/rdoc/classes/Web.src/M000008.html +1 -1
  18. data/doc/rdoc/classes/Web.src/M000009.html +1 -1
  19. data/doc/rdoc/classes/Web/CGD.src/M000038.html +2 -1
  20. data/doc/rdoc/classes/Web/CGD.src/M000039.html +1 -1
  21. data/doc/rdoc/classes/Web/CGD.src/M000040.html +1 -1
  22. data/doc/rdoc/classes/Web/CGD.src/M000041.html +1 -1
  23. data/doc/rdoc/classes/Web/CGI.src/M000105.html +1 -1
  24. data/doc/rdoc/classes/Web/CGI.src/M000106.html +1 -1
  25. data/doc/rdoc/classes/Web/CGI.src/M000107.html +1 -1
  26. data/doc/rdoc/classes/Web/Narflates.html +4 -2
  27. data/doc/rdoc/classes/Web/Testing.src/M000027.html +1 -4
  28. data/doc/rdoc/classes/Web/Testing.src/M000028.html +1 -2
  29. data/doc/rdoc/classes/Web/Testing.src/M000029.html +1 -1
  30. data/doc/rdoc/classes/Web/Testing.src/M000030.html +1 -1
  31. data/doc/rdoc/classes/Web/Testing.src/M000031.html +1 -1
  32. data/doc/rdoc/classes/Web/Testing.src/M000032.html +1 -1
  33. data/doc/rdoc/classes/Web/Testing.src/M000033.html +1 -1
  34. data/doc/rdoc/classes/Web/Testing.src/M000034.html +1 -1
  35. data/doc/rdoc/classes/Web/Testing.src/M000035.html +1 -1
  36. data/doc/rdoc/classes/Web/Testing.src/M000036.html +1 -1
  37. data/doc/rdoc/created.rid +1 -1
  38. data/doc/rdoc/files/README.html +7 -3
  39. data/doc/rdoc/files/doc/apache_cgi_txt.html +3 -9
  40. data/doc/rdoc/files/doc/fastcgi_txt.html +2 -2
  41. data/doc/rdoc/files/lib/web/cgi_rb.html +1 -1
  42. data/doc/rdoc/files/lib/web/parser_rb.html +1 -1
  43. data/doc/rdoc/files/lib/web/template_rb.html +1 -1
  44. data/doc/rdoc/files/lib/web/testing_rb.html +1 -1
  45. data/doc/rdoc/files/lib/web/wiki_rb.html +1 -1
  46. data/doc/rdoc/files/lib/web_rb.html +1 -1
  47. data/lib/web.rb +127 -20
  48. data/lib/web/parser.rb +25 -7
  49. data/lib/web/parser.rb~ +30 -8
  50. data/lib/web/template.rb +6 -4
  51. data/lib/web/wiki.rb +23 -12
  52. data/lib/web/wiki.rb~ +1 -1
  53. data/narf-0.5.1.gem +0 -0
  54. data/narf.gemspec +1 -1
  55. data/narf.gemspec~ +18 -30
  56. data/test/test.request.rb +33 -20
  57. data/test/test.request.rb~ +10 -0
  58. data/test/testfiles/mac_ie_env.yaml +32 -0
  59. data/test/testfiles/mac_ie_stdin.bin +0 -0
  60. data/test/testfiles/mac_safari_stdin.bin +0 -0
  61. data/test/wiki/test.tarpit.rb +16 -0
  62. data/test/wiki/test.tarpit.rb~ +40 -0
  63. metadata +9 -3
  64. data/vandals.test.txt +0 -3
@@ -7,7 +7,7 @@
7
7
  <link rel=StyleSheet href="../../.././rdoc-style.css" type="text/css" media="screen" />
8
8
  </head>
9
9
  <body bgcolor="white">
10
- <pre><span class="cmt"># File lib/web/cgi.rb, line 628</span>
10
+ <pre><span class="cmt"># File lib/web/cgi.rb, line 629</span>
11
11
  <span class="kw">def</span> CGI::process( options={}, &amp;block )
12
12
  <span class="kw">if</span> CGI::server_sniff == :fcgi
13
13
  FCGI::each_request{ |fcgi|
@@ -79,14 +79,16 @@ template merged with values:
79
79
  </p>
80
80
  <pre>
81
81
  --- script.rb:
82
- Web.print_template &quot;mytemplate.html&quot;,
82
+ Web::process do
83
+ Web.print_template &quot;mytemplate.html&quot;,
83
84
  &quot;field1&quot; =&gt; &quot;val1&quot;,
84
85
  &quot;field2&quot; =&gt; &quot;val2&quot;,
85
- &quot;field3&quot; =&gt; &quot;val3&quot;,
86
+ &quot;field3&quot; =&gt; &quot;val3&quot;,
86
87
  &quot;field4&quot; =&gt; &quot;3&quot;,
87
88
  &quot;values&quot; =&gt; [{ &quot;name&quot; =&gt; &quot;one&quot;, &quot;value&quot; =&gt; &quot;1&quot;},
88
89
  { &quot;name&quot; =&gt; &quot;two&quot;, &quot;value&quot; =&gt; &quot;2&quot;},
89
90
  { &quot;name' =&gt; &quot;three&quot;, &quot;value&quot; =&gt; &quot;3&quot;}]
91
+ end
90
92
 
91
93
  --- mytemplate.html:
92
94
  &lt;narf:input type=&quot;text&quot; name=&quot;field1&quot;&gt;
@@ -19,10 +19,7 @@
19
19
 
20
20
  options[:path_info] = path_info
21
21
  options[:script_name] = script_name
22
-
23
- Web.set_cgi CGI.new(options)
24
-
25
- load_request( script_path, webpath )
22
+ load_request( options, script_path, webpath )
26
23
  <span class="kw">end</span></pre>
27
24
  </body>
28
25
  </html>
@@ -50,9 +50,8 @@
50
50
 
51
51
  options[:path_info] = path_info <span class="cmt">#oldRequest.path_info</span>
52
52
  options[:script_name] = script_name <span class="cmt">#oldRequest.script_name</span>
53
- Web.set_cgi CGI.new( options )
54
53
 
55
- load_request( script_path, webpath )
54
+ load_request( options, script_path, webpath )
56
55
  <span class="kw">end</span></pre>
57
56
  </body>
58
57
  </html>
@@ -7,7 +7,7 @@
7
7
  <link rel=StyleSheet href="../../.././rdoc-style.css" type="text/css" media="screen" />
8
8
  </head>
9
9
  <body bgcolor="white">
10
- <pre><span class="cmt"># File lib/web/testing.rb, line 326</span>
10
+ <pre><span class="cmt"># File lib/web/testing.rb, line 325</span>
11
11
  <span class="kw">def</span> assert_template_used filename, msg=<span class="str">&quot;&quot;</span>
12
12
  Web.assert_template_used filename, msg
13
13
  <span class="kw">end</span></pre>
@@ -7,7 +7,7 @@
7
7
  <link rel=StyleSheet href="../../.././rdoc-style.css" type="text/css" media="screen" />
8
8
  </head>
9
9
  <body bgcolor="white">
10
- <pre><span class="cmt"># File lib/web/testing.rb, line 331</span>
10
+ <pre><span class="cmt"># File lib/web/testing.rb, line 330</span>
11
11
  <span class="kw">def</span> assert_template_not_used filename, msg=<span class="str">&quot;&quot;</span>
12
12
  Web.assert_template_not_used filename, msg
13
13
  <span class="kw">end</span></pre>
@@ -7,7 +7,7 @@
7
7
  <link rel=StyleSheet href="../../.././rdoc-style.css" type="text/css" media="screen" />
8
8
  </head>
9
9
  <body bgcolor="white">
10
- <pre><span class="cmt"># File lib/web/testing.rb, line 336</span>
10
+ <pre><span class="cmt"># File lib/web/testing.rb, line 335</span>
11
11
  <span class="kw">def</span> assert_vars_includes expected
12
12
  Web.assert_vars_includes expected
13
13
  <span class="kw">end</span></pre>
@@ -7,7 +7,7 @@
7
7
  <link rel=StyleSheet href="../../.././rdoc-style.css" type="text/css" media="screen" />
8
8
  </head>
9
9
  <body bgcolor="white">
10
- <pre><span class="cmt"># File lib/web/testing.rb, line 341</span>
10
+ <pre><span class="cmt"># File lib/web/testing.rb, line 340</span>
11
11
  <span class="kw">def</span> assert_form_includes formname, expected
12
12
  Web.assert_form_includes formname, expected
13
13
  <span class="kw">end</span></pre>
@@ -7,7 +7,7 @@
7
7
  <link rel=StyleSheet href="../../.././rdoc-style.css" type="text/css" media="screen" />
8
8
  </head>
9
9
  <body bgcolor="white">
10
- <pre><span class="cmt"># File lib/web/testing.rb, line 346</span>
10
+ <pre><span class="cmt"># File lib/web/testing.rb, line 345</span>
11
11
  <span class="kw">def</span> assert_content expected, msg=<span class="str">&quot;&quot;</span>
12
12
  Web.assert_content expected, msg
13
13
  <span class="kw">end</span></pre>
@@ -7,7 +7,7 @@
7
7
  <link rel=StyleSheet href="../../.././rdoc-style.css" type="text/css" media="screen" />
8
8
  </head>
9
9
  <body bgcolor="white">
10
- <pre><span class="cmt"># File lib/web/testing.rb, line 351</span>
10
+ <pre><span class="cmt"># File lib/web/testing.rb, line 350</span>
11
11
  <span class="kw">def</span> assert_header key, value, msg=<span class="str">&quot;&quot;</span>
12
12
  Web.assert_header key, value, msg
13
13
  <span class="kw">end</span></pre>
@@ -7,7 +7,7 @@
7
7
  <link rel=StyleSheet href="../../.././rdoc-style.css" type="text/css" media="screen" />
8
8
  </head>
9
9
  <body bgcolor="white">
10
- <pre><span class="cmt"># File lib/web/testing.rb, line 356</span>
10
+ <pre><span class="cmt"># File lib/web/testing.rb, line 355</span>
11
11
  <span class="kw">def</span> assert_cookie key, value, msg=<span class="str">&quot;&quot;</span>
12
12
  Web.assert_cookie key, value, msg
13
13
  <span class="kw">end</span></pre>
@@ -7,7 +7,7 @@
7
7
  <link rel=StyleSheet href="../../.././rdoc-style.css" type="text/css" media="screen" />
8
8
  </head>
9
9
  <body bgcolor="white">
10
- <pre><span class="cmt"># File lib/web/testing.rb, line 362</span>
10
+ <pre><span class="cmt"># File lib/web/testing.rb, line 361</span>
11
11
  <span class="kw">def</span> assert_options( formname, expected={})
12
12
  options = Web.get_formreader.get_options(formname)
13
13
  expected.each{ |k,v|
@@ -1 +1 @@
1
- Sun Oct 03 11:48:05 EDT 2004
1
+ Tue Nov 02 01:22:31 EST 2004
@@ -29,7 +29,7 @@
29
29
  </tr>
30
30
  <tr>
31
31
  <td class="small-title-font">Modified:</td>
32
- <td class="small-title-font">Fri Sep 03 19:03:47 EDT 2004</td>
32
+ <td class="small-title-font">Tue Nov 02 01:15:43 EST 2004</td>
33
33
  </tr>
34
34
  </table>
35
35
  </td></tr></table></td>
@@ -124,7 +124,9 @@ for this:
124
124
  <h3>Hello World</h3>
125
125
  <pre>
126
126
  require 'web'
127
- Web &lt;&lt; 'Hello World'
127
+ Web::process do
128
+ Web &lt;&lt; 'Hello World'
129
+ end
128
130
  </pre>
129
131
  <h3>Testing an App</h3>
130
132
  <p>
@@ -142,7 +144,9 @@ where script.rb is:
142
144
  #!/usr/bin/ruby
143
145
  require 'web'
144
146
 
145
- Web &lt;&lt; &quot;param is #{Web[&quot;param&quot;]}&quot;
147
+ Web::process do
148
+ Web &lt;&lt; &quot;param is #{Web[&quot;param&quot;]}&quot;
149
+ end
146
150
  </pre>
147
151
  <p>
148
152
  and test.rb is:
@@ -29,7 +29,7 @@
29
29
  </tr>
30
30
  <tr>
31
31
  <td class="small-title-font">Modified:</td>
32
- <td class="small-title-font">Sun Oct 03 11:14:33 EDT 2004</td>
32
+ <td class="small-title-font">Tue Nov 02 01:21:59 EST 2004</td>
33
33
  </tr>
34
34
  </table>
35
35
  </td></tr></table></td>
@@ -60,14 +60,8 @@ run it with a shebang:
60
60
  #!/usr/local/bin/narf
61
61
  </pre>
62
62
  <p>
63
- This file may likely has a buffer overflow in it. Please be cautious with
64
- this until I can get verification that it is ok.
65
- </p>
66
- <p>
67
- Cheers,
68
- </p>
69
- <p>
70
- patrick@hexane.org
63
+ This file may have a buffer overflow in it. Please be cautious with this
64
+ until I can get verification that it is ok.
71
65
  </p>
72
66
  </div>
73
67
 
@@ -29,7 +29,7 @@
29
29
  </tr>
30
30
  <tr>
31
31
  <td class="small-title-font">Modified:</td>
32
- <td class="small-title-font">Sun Oct 03 11:14:52 EDT 2004</td>
32
+ <td class="small-title-font">Tue Nov 02 01:20:38 EST 2004</td>
33
33
  </tr>
34
34
  </table>
35
35
  </td></tr></table></td>
@@ -58,7 +58,7 @@ you will need to make sure that the cgi script executes in a Web::process
58
58
  block:
59
59
  </p>
60
60
  <pre>
61
- #!/usr/local/bin/ruby
61
+ #!/usr/local/bin/ruby -rweb
62
62
 
63
63
  Web::process{
64
64
  Web &lt;&lt; 'Hello World!'
@@ -29,7 +29,7 @@
29
29
  </tr>
30
30
  <tr>
31
31
  <td class="small-title-font">Modified:</td>
32
- <td class="small-title-font">Fri Oct 01 20:10:58 EDT 2004</td>
32
+ <td class="small-title-font">Sun Oct 03 16:48:10 EDT 2004</td>
33
33
  </tr>
34
34
  </table>
35
35
  </td></tr></table></td>
@@ -29,7 +29,7 @@
29
29
  </tr>
30
30
  <tr>
31
31
  <td class="small-title-font">Modified:</td>
32
- <td class="small-title-font">Sun Oct 03 11:32:07 EDT 2004</td>
32
+ <td class="small-title-font">Sun Oct 31 17:01:53 EST 2004</td>
33
33
  </tr>
34
34
  </table>
35
35
  </td></tr></table></td>
@@ -29,7 +29,7 @@
29
29
  </tr>
30
30
  <tr>
31
31
  <td class="small-title-font">Modified:</td>
32
- <td class="small-title-font">Sun Sep 26 15:20:23 EDT 2004</td>
32
+ <td class="small-title-font">Tue Nov 02 01:18:42 EST 2004</td>
33
33
  </tr>
34
34
  </table>
35
35
  </td></tr></table></td>
@@ -29,7 +29,7 @@
29
29
  </tr>
30
30
  <tr>
31
31
  <td class="small-title-font">Modified:</td>
32
- <td class="small-title-font">Sun Oct 03 11:31:25 EDT 2004</td>
32
+ <td class="small-title-font">Sun Oct 03 16:49:53 EDT 2004</td>
33
33
  </tr>
34
34
  </table>
35
35
  </td></tr></table></td>
@@ -29,7 +29,7 @@
29
29
  </tr>
30
30
  <tr>
31
31
  <td class="small-title-font">Modified:</td>
32
- <td class="small-title-font">Sun Oct 03 11:34:00 EDT 2004</td>
32
+ <td class="small-title-font">Sun Oct 03 16:46:52 EDT 2004</td>
33
33
  </tr>
34
34
  </table>
35
35
  </td></tr></table></td>
@@ -29,7 +29,7 @@
29
29
  </tr>
30
30
  <tr>
31
31
  <td class="small-title-font">Modified:</td>
32
- <td class="small-title-font">Sun Oct 03 10:39:14 EDT 2004</td>
32
+ <td class="small-title-font">Tue Nov 02 01:16:55 EST 2004</td>
33
33
  </tr>
34
34
  </table>
35
35
  </td></tr></table></td>
data/lib/web.rb CHANGED
@@ -78,12 +78,15 @@ end
78
78
  # Use the Web module to interact with the client. The module
79
79
  # delegates to a Web::CGI object, which does the actual work.
80
80
  #
81
- # #!/usr/bin/narf
82
- # Web["field"] # access parameters
83
- # Web.cookies["muppet"] # access cookies
84
- # Web.session["key"] ||= "value" # get and set session values
85
- # Web.set_cookie( "muppet", "cookie monster" ) # set cookies
86
- # Web.puts "something" # print 'something' out
81
+ # #!/usr/bin/ruby
82
+ # require 'web'
83
+ # Web::process do
84
+ # Web["field"] # access parameters
85
+ # Web.cookies["muppet"] # access cookies
86
+ # Web.session["key"] ||= "value" # get and set session values
87
+ # Web.set_cookie( "muppet", "cookie monster" ) # set cookies
88
+ # Web.puts "something" # print 'something' out
89
+ # end
87
90
  #
88
91
  # If the request contained multipart/form-data, uploaded files are returned as
89
92
  # Web::Upload objects. Other parameters are treated as strings.
@@ -176,18 +179,10 @@ module Web
176
179
  end
177
180
  end
178
181
 
179
- # this is a bit incomplete -- only encodes ampersands
180
- def Web::html_encode(string)
181
- return nil unless string
182
- newstring = string.dup
183
- { /&/ => '&amp;' }.each{ |char, entity|
184
- newstring.gsub!( char, entity )
185
- }
186
- newstring
187
- end
188
-
189
- # Escape URL encode
190
- # url_encoded_string = Web::escape("string")
182
+ # URL-encode a string.
183
+ # url_encoded_string = Web::escape("'Stop!' said Fred")
184
+ # # => "%27Stop%21%27+said+Fred"
185
+ # (from cgi.rb)
191
186
  def Web::escape(string)
192
187
  return nil unless string
193
188
  string.gsub(/([^ a-zA-Z0-9_.-]+)/n) do
@@ -195,8 +190,11 @@ module Web
195
190
  end.tr(' ', '+')
196
191
  end
197
192
 
198
- # Unescape URL encoded
199
- # string = Web::unescape("url encoded string")
193
+
194
+ # URL-decode a string.
195
+ # string = Web::unescape("%27Stop%21%27+said+Fred")
196
+ # # => "'Stop!' said Fred"
197
+ # (from cgi.rb)
200
198
  def Web::unescape(string)
201
199
  return nil unless string
202
200
  string.tr('+', ' ').gsub(/((?:%[0-9a-fA-F]{2})+)/n) do
@@ -204,6 +202,115 @@ module Web
204
202
  end
205
203
  end
206
204
 
205
+
206
+ # Escape special characters in HTML, namely &\"<>
207
+ # Web::escape_html('Usage: foo "bar" <baz>')
208
+ # # => "Usage: foo &quot;bar&quot; &lt;baz&gt;"
209
+ # (from cgi.rb)
210
+ def Web::escape_html(string)
211
+ return nil unless string
212
+ string.gsub(/&/n, '&amp;').gsub(/\"/n, '&quot;').gsub(/>/n, '&gt;').gsub(/</n, '&lt;')
213
+ end
214
+
215
+
216
+ # Unescape a string that has been HTML-escaped
217
+ # Web::unescape_html("Usage: foo &quot;bar&quot; &lt;baz&gt;")
218
+ # # => "Usage: foo \"bar\" <baz>"
219
+ # (from cgi.rb)
220
+ def Web::unescape_html(string)
221
+ return nil unless string
222
+ string.gsub(/&(.*?);/n) do
223
+ match = $1.dup
224
+ case match
225
+ when /\Aamp\z/ni then '&'
226
+ when /\Aquot\z/ni then '"'
227
+ when /\Agt\z/ni then '>'
228
+ when /\Alt\z/ni then '<'
229
+ when /\A#0*(\d+)\z/n then
230
+ if Integer($1) < 256
231
+ Integer($1).chr
232
+ else
233
+ if Integer($1) < 65536 and ($KCODE[0] == ?u or $KCODE[0] == ?U)
234
+ [Integer($1)].pack("U")
235
+ else
236
+ "&##{$1};"
237
+ end
238
+ end
239
+ when /\A#x([0-9a-f]+)\z/ni then
240
+ if $1.hex < 256
241
+ $1.hex.chr
242
+ else
243
+ if $1.hex < 65536 and ($KCODE[0] == ?u or $KCODE[0] == ?U)
244
+ [$1.hex].pack("U")
245
+ else
246
+ "&#x#{$1};"
247
+ end
248
+ end
249
+ else
250
+ "&#{match};"
251
+ end
252
+ end
253
+ end
254
+
255
+
256
+ # Escape only the tags of certain HTML elements in +string+.
257
+ #
258
+ # Takes an element or elements or array of elements. Each element
259
+ # is specified by the name of the element, without angle brackets.
260
+ # This matches both the start and the end tag of that element.
261
+ # The attribute list of the open tag will also be escaped (for
262
+ # instance, the double-quotes surrounding attribute values).
263
+ #
264
+ # print Web::escape_element('<BR><A HREF="url"></A>', "A", "IMG")
265
+ # # "<BR>&lt;A HREF=&quot;url&quot;&gt;&lt;/A&gt"
266
+ #
267
+ # print Web::escape_element('<BR><A HREF="url"></A>', ["A", "IMG"])
268
+ # # "<BR>&lt;A HREF=&quot;url&quot;&gt;&lt;/A&gt"
269
+ #
270
+ # (from cgi.rb)
271
+ def Web::escape_element(string, *elements)
272
+ return nil unless string
273
+ elements = elements[0] if elements[0].kind_of?(Array)
274
+ unless elements.empty?
275
+ string.gsub(/<\/?(?:#{elements.join("|")})(?!\w)(?:.|\n)*?>/ni) do
276
+ Web::escape_html($&)
277
+ end
278
+ else
279
+ string
280
+ end
281
+ end
282
+
283
+
284
+ # Undo escaping such as that done by Web::escape_element()
285
+ #
286
+ # print Web::unescape_element(
287
+ # Web::escapeHTML('<BR><A HREF="url"></A>'), "A", "IMG")
288
+ # # "&lt;BR&gt;<A HREF="url"></A>"
289
+ #
290
+ # print Web::unescape_element(
291
+ # Web::escapeHTML('<BR><A HREF="url"></A>'), ["A", "IMG"])
292
+ # # "&lt;BR&gt;<A HREF="url"></A>"
293
+ # (from cgi.rb)
294
+ def Web::unescape_element(string, *elements)
295
+ return nil unless string
296
+ elements = elements[0] if elements[0].kind_of?(Array)
297
+ unless elements.empty?
298
+ string.gsub(/&lt;\/?(?:#{elements.join("|")})(?!\w)(?:.|\n)*?&gt;/ni) do
299
+ Web::unescape_html($&)
300
+ end
301
+ else
302
+ string
303
+ end
304
+ end
305
+
306
+ class << self
307
+ alias escapeHTML escape_html
308
+ alias html_encode escape_html
309
+ alias unescapeHTML unescape_html
310
+ alias escapeElement escape_element
311
+ alias unescapeElement unescape_element
312
+ end
313
+
207
314
  RFC822_DAYS = %w[ Sun Mon Tue Wed Thu Fri Sat ]
208
315
  RFC822_MONTHS = %w[ Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ]
209
316
  # Make RFC1123 date string
@@ -189,20 +189,32 @@ module Web
189
189
  raise EOFError, "no content body"
190
190
  end
191
191
 
192
+ # ok... so what the hell does this do?
193
+ # I promise never to denigrate the accomplishments
194
+ # of my predecessors again :-)
195
+ # ~ pat
192
196
  until -1 == content_length
193
197
  head = nil
194
198
  body = Tempfile.new("Web")
195
199
  body.binmode
196
200
 
201
+ # until we have:
202
+ # * a header
203
+ # * and a buffer that has a boundary
204
+ # so far, make sense to me.
197
205
  until head and /#{boundary}(?:#{EOL}|--)/n.match(buf)
198
-
206
+ # if we have a header....
199
207
  if head
208
+ # !??!??!?!?!
200
209
  trim_size = (EOL + boundary + EOL).size
201
210
  if trim_size < buf.size
202
211
  body.print buf[0 ... (buf.size - trim_size)]
203
212
  buf[0 ... (buf.size - trim_size)] = ""
204
213
  end
214
+
215
+ # If we have a double space (the smell of a header...)
205
216
  elsif /#{EOL}#{EOL}/n.match(buf)
217
+ # extract the header, and erase it from the buffer
206
218
  buf = buf.sub(/\A((?:.|\n)*?#{EOL})#{EOL}/n) do
207
219
  head = $1.dup
208
220
  ""
@@ -210,18 +222,18 @@ module Web
210
222
  next
211
223
  end
212
224
 
225
+ # read a chunk from the input
213
226
  c = if bufsize < content_length
214
227
  input.read(bufsize) or ''
215
228
  else
216
229
  input.read(content_length) or ''
217
230
  end
231
+ # add it to the input, reduce our countdown
218
232
  buf.concat c
219
233
  content_length -= c.size
220
-
221
234
  end
222
235
 
223
-
224
- /Content-Disposition:.* filename="?([^\";]*)"?/ni.match(head)
236
+ /Content-Disposition:.* filename="?([^\";]*)"?/ni.match(head)
225
237
  filename = ($1 or "").dup
226
238
  if /Mac/ni.match(env['http_user_agent']) and
227
239
  /Mozilla/ni.match(env['http_user_agent']) and
@@ -232,7 +244,9 @@ module Web
232
244
  /Content-Type: (.*)/ni.match(head)
233
245
  content_type = ($1 or "").strip
234
246
 
235
- buf = buf.sub(/\A((?:.|\n)*?)(?:#{EOL})?#{boundary}(#{EOL}|--)/n) do
247
+ # is this the part that is eating too much?
248
+ #buf = buf.sub(/\A(.*?)(?:#{EOL})?#{boundary}(#{EOL}|--)/mn) do
249
+ buf = buf.sub(/\A((?:.|\n)*?)(?:[\r\n]{1,2})?#{boundary}([\r\n]{1,2}|--)/n) do
236
250
  body.print $1
237
251
  if "--" == $2
238
252
  content_length = -1
@@ -241,7 +255,8 @@ module Web
241
255
  end
242
256
 
243
257
  body.rewind
244
-
258
+
259
+
245
260
  if (content_type.empty?)
246
261
  upload = body.read
247
262
  else
@@ -250,7 +265,10 @@ module Web
250
265
 
251
266
  /Content-Disposition:.* name="?([^\";]*)"?/ni.match(head)
252
267
  name = $1.dup
253
-
268
+
269
+
270
+ body.rewind
271
+
254
272
  if params.has_key?(name)
255
273
  params[name].push(upload)
256
274
  else