4
4
5
5
cgi.rb - cgi support library
6
6
7
- Version 2.1.0
7
+ Version 2.1.1
8
8
9
9
Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
10
10
@@ -185,10 +185,10 @@ class CGI
185
185
CR = "\015 "
186
186
LF = "\012 "
187
187
EOL = CR + LF
188
- VERSION = "2.1.0 "
189
- RELEASE_DATE = "2000-10-12 "
190
- VERSION_CODE = 210
191
- RELEASE_CODE = 20001012
188
+ VERSION = "2.1.1 "
189
+ RELEASE_DATE = "2000-12-14 "
190
+ VERSION_CODE = 211
191
+ RELEASE_CODE = 20001214
192
192
193
193
NEEDS_BINMODE = true if /WIN/ni === RUBY_PLATFORM
194
194
PATH_SEPARATOR = { 'UNIX' => '/' , 'WINDOWS' => '\\' , 'MACINTOSH' => ':' }
@@ -241,7 +241,7 @@ def stdoutput
241
241
=end
242
242
def CGI ::escape ( string )
243
243
string . gsub ( /([^ a-zA-Z0-9_.-]+)/n ) do
244
- '%' + $1 . unpack ( 'H2' * $1 . size ) . join ( '%' ) . upcase
244
+ '%' + Regexp :: last_match [ 1 ] . unpack ( 'H2' * Regexp :: last_match [ 1 ] . size ) . join ( '%' ) . upcase
245
245
end . tr ( ' ' , '+' )
246
246
end
247
247
@@ -252,7 +252,7 @@ def CGI::escape(string)
252
252
=end
253
253
def CGI ::unescape ( string )
254
254
string . tr ( '+' , ' ' ) . gsub ( /((?:%[0-9a-fA-F]{2})+)/n ) do
255
- [ $1 . delete ( '%' ) ] . pack ( 'H*' )
255
+ [ Regexp :: last_match [ 1 ] . delete ( '%' ) ] . pack ( 'H*' )
256
256
end
257
257
end
258
258
@@ -272,34 +272,34 @@ def CGI::escapeHTML(string)
272
272
=end
273
273
def CGI ::unescapeHTML ( string )
274
274
string . gsub ( /&(.*?);/n ) do
275
- match = $1 . dup
275
+ match = Regexp :: last_match [ 1 ] . dup
276
276
case match
277
277
when /\A amp\z /ni then '&'
278
278
when /\A quot\z /ni then '"'
279
279
when /\A gt\z /ni then '>'
280
280
when /\A lt\z /ni then '<'
281
281
when /\A #(\d +)\z /n then
282
- if Integer ( $1 ) < 256
283
- Integer ( $1 ) . chr
282
+ if Integer ( Regexp :: last_match [ 1 ] ) < 256
283
+ Integer ( Regexp :: last_match [ 1 ] ) . chr
284
284
else
285
- if Integer ( $1 ) < 65536 and ( $KCODE[ 0 ] == ?u or $KCODE[ 0 ] == ?U)
286
- [ Integer ( $1 ) ] . pack ( "U" )
285
+ if Integer ( Regexp :: last_match [ 1 ] ) < 65536 and ( $KCODE[ 0 ] == ?u or $KCODE[ 0 ] == ?U)
286
+ [ Integer ( Regexp :: last_match [ 1 ] ) ] . pack ( "U" )
287
287
else
288
- "&##{ $1 } ;"
288
+ "&##{ Regexp :: last_match [ 1 ] } ;"
289
289
end
290
290
end
291
291
when /\A #x([0-9a-f]+)\z /ni then
292
- if $1 . hex < 256
293
- $1 . hex . chr
292
+ if Regexp :: last_match [ 1 ] . hex < 256
293
+ Regexp :: last_match [ 1 ] . hex . chr
294
294
else
295
- if $1 . hex < 65536 and ( $KCODE[ 0 ] == ?u or $KCODE[ 0 ] == ?U)
296
- [ $1 . hex ] . pack ( "U" )
295
+ if Regexp :: last_match [ 1 ] . hex < 65536 and ( $KCODE[ 0 ] == ?u or $KCODE[ 0 ] == ?U)
296
+ [ Regexp :: last_match [ 1 ] . hex ] . pack ( "U" )
297
297
else
298
- "&#x#{ $1 } ;"
298
+ "&#x#{ Regexp :: last_match [ 1 ] } ;"
299
299
end
300
300
end
301
301
else
302
- "&#{ $1 } ;"
302
+ "&#{ Regexp :: last_match [ 1 ] } ;"
303
303
end
304
304
end
305
305
end
@@ -316,7 +316,7 @@ def CGI::unescapeHTML(string)
316
316
def CGI ::escapeElement ( string , *element )
317
317
unless element . empty?
318
318
string . gsub ( /<\/ ?(?:#{ element . join ( "|" ) } )(?!\w )(?:.|\n )*?>/ni ) do
319
- CGI ::escapeHTML ( $& )
319
+ CGI ::escapeHTML ( Regexp :: last_match [ 0 ] )
320
320
end
321
321
else
322
322
string
@@ -336,7 +336,7 @@ def CGI::escapeElement(string, *element)
336
336
=end
337
337
def CGI ::unescapeElement ( string , *element )
338
338
string . gsub ( /<\/ ?(?:#{ element . join ( "|" ) } )(?!\w )(?:.|\n )*?>/ni ) do
339
- CGI ::unescapeHTML ( $& )
339
+ CGI ::unescapeHTML ( Regexp :: last_match [ 0 ] )
340
340
end
341
341
end
342
342
@@ -491,7 +491,7 @@ def header(options = "text/html")
491
491
492
492
if defined? ( MOD_RUBY )
493
493
buf . scan ( /([^:]+): (.+)#{ EOL } /n ) {
494
- Apache ::request [ $1 ] = $2
494
+ Apache ::request [ Regexp :: last_match [ 1 ] ] = Regexp :: last_match [ 2 ]
495
495
}
496
496
Apache ::request . send_http_header
497
497
''
@@ -787,7 +787,7 @@ def read_multipart(boundary, content_length)
787
787
788
788
if ( not head ) and ( /#{ EOL } #{ EOL } /n === buf )
789
789
buf = buf . sub ( /\A ((?:.|\n )*?#{ EOL } )#{ EOL } /n ) do
790
- head = $1 . dup
790
+ head = Regexp :: last_match [ 1 ] . dup
791
791
""
792
792
end
793
793
next
@@ -809,8 +809,8 @@ def read_multipart(boundary, content_length)
809
809
end
810
810
811
811
buf = buf . sub ( /\A ((?:.|\n )*?)(?:#{ EOL } )?#{ boundary } (#{ EOL } |--)/n ) do
812
- body . print $1
813
- if "--" == $2
812
+ body . print Regexp :: last_match [ 1 ]
813
+ if "--" == Regexp :: last_match [ 2 ]
814
814
content_length = -1
815
815
end
816
816
""
@@ -828,27 +828,27 @@ def body.local_path
828
828
eval <<-END
829
829
def body.original_filename
830
830
#{
831
- filename = ( $1 or "" ) . dup
831
+ filename = ( Regexp :: last_match [ 1 ] or "" ) . dup
832
832
if ( /Mac/ni === env_table [ 'HTTP_USER_AGENT' ] ) and
833
833
( /Mozilla/ni === env_table [ 'HTTP_USER_AGENT' ] ) and
834
834
( not /MSIE/ni === env_table [ 'HTTP_USER_AGENT' ] )
835
835
CGI ::unescape ( filename )
836
836
else
837
837
filename
838
- end . dump
839
- }
838
+ end . dump . untaint
839
+ } .taint
840
840
end
841
841
END
842
842
843
843
/Content-Type: (.*)/ni === head
844
844
eval <<-END
845
845
def body.content_type
846
- #{ ( $1 or "" ) . dump }
846
+ #{ ( Regexp :: last_match [ 1 ] or "" ) . dump . untaint } .taint
847
847
end
848
848
END
849
849
850
850
/Content-Disposition:.* name="?([^\" ;]*)"?/ni === head
851
- name = $1 . dup
851
+ name = Regexp :: last_match [ 1 ] . dup
852
852
853
853
if params . has_key? ( name )
854
854
params [ name ] . push ( body )
@@ -891,7 +891,7 @@ def initialize_query()
891
891
if ( "POST" == env_table [ 'REQUEST_METHOD' ] ) and
892
892
( %r|\A multipart/form-data.*boundary=\" ?([^\" ;,]+)\" ?|n ===
893
893
env_table [ 'CONTENT_TYPE' ] )
894
- boundary = $1 . dup
894
+ boundary = Regexp :: last_match [ 1 ] . dup
895
895
@params = read_multipart ( boundary , Integer ( env_table [ 'CONTENT_LENGTH' ] ) )
896
896
else
897
897
@params = CGI ::parse (
@@ -951,7 +951,7 @@ def CGI::pretty(string, shift = " ")
951
951
lines = string . gsub ( /(?!\A )<(?:.|\n )*?>/n , "\n \\ 0" ) . gsub ( /<(?:.|\n )*?>(?!\n )/n , "\\ 0\n " )
952
952
end_pos = 0
953
953
while end_pos = lines . index ( /^<\/ (\w +)/n , end_pos )
954
- element = $1 . dup
954
+ element = Regexp :: last_match [ 1 ] . dup
955
955
start_pos = lines . rindex ( /^\s *<#{ element } /ni , end_pos )
956
956
lines [ start_pos ... end_pos ] = "__" + lines [ start_pos ... end_pos ] . gsub ( /\n (?!\z )/n , "\n " + shift ) + "__"
957
957
end
@@ -1925,6 +1925,15 @@ def initialize(type = "query")
1925
1925
1926
1926
== HISTORY
1927
1927
1928
+ * Mon Dec 11 00:16:51 JST 2000 - wakou
1929
+ * version 2.1.1
1930
+ * support -T1 on ruby 1.6.2
1931
+ * body.original_filename: eval(str.dump.untaint).taint
1932
+ * body.content_type: eval(str.dump.untaint).taint
1933
+ * $& --> Regexp::last_match[0]
1934
+ * $1 --> Regexp::last_match[1]
1935
+ * $2 --> Regexp::last_match[2]
1936
+
1928
1937
* Thu Oct 12 01:16:59 JST 2000 - wakou
1929
1938
* version 2.1.0
1930
1939
* bug fix: CGI::html(): PRETTY option didn't work.
0 commit comments