Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby18/lib64/ruby/1.8
File: cgi.rb
#
[0] Fix | Delete
# cgi.rb - cgi support library
[1] Fix | Delete
#
[2] Fix | Delete
# Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
[3] Fix | Delete
#
[4] Fix | Delete
# Copyright (C) 2000 Information-technology Promotion Agency, Japan
[5] Fix | Delete
#
[6] Fix | Delete
# Author: Wakou Aoyama <wakou@ruby-lang.org>
[7] Fix | Delete
#
[8] Fix | Delete
# Documentation: Wakou Aoyama (RDoc'd and embellished by William Webber)
[9] Fix | Delete
#
[10] Fix | Delete
# == Overview
[11] Fix | Delete
#
[12] Fix | Delete
# The Common Gateway Interface (CGI) is a simple protocol
[13] Fix | Delete
# for passing an HTTP request from a web server to a
[14] Fix | Delete
# standalone program, and returning the output to the web
[15] Fix | Delete
# browser. Basically, a CGI program is called with the
[16] Fix | Delete
# parameters of the request passed in either in the
[17] Fix | Delete
# environment (GET) or via $stdin (POST), and everything
[18] Fix | Delete
# it prints to $stdout is returned to the client.
[19] Fix | Delete
#
[20] Fix | Delete
# This file holds the +CGI+ class. This class provides
[21] Fix | Delete
# functionality for retrieving HTTP request parameters,
[22] Fix | Delete
# managing cookies, and generating HTML output. See the
[23] Fix | Delete
# class documentation for more details and examples of use.
[24] Fix | Delete
#
[25] Fix | Delete
# The file cgi/session.rb provides session management
[26] Fix | Delete
# functionality; see that file for more details.
[27] Fix | Delete
#
[28] Fix | Delete
# See http://www.w3.org/CGI/ for more information on the CGI
[29] Fix | Delete
# protocol.
[30] Fix | Delete
[31] Fix | Delete
raise "Please, use ruby 1.5.4 or later." if RUBY_VERSION < "1.5.4"
[32] Fix | Delete
[33] Fix | Delete
require 'English'
[34] Fix | Delete
[35] Fix | Delete
# CGI class. See documentation for the file cgi.rb for an overview
[36] Fix | Delete
# of the CGI protocol.
[37] Fix | Delete
#
[38] Fix | Delete
# == Introduction
[39] Fix | Delete
#
[40] Fix | Delete
# CGI is a large class, providing several categories of methods, many of which
[41] Fix | Delete
# are mixed in from other modules. Some of the documentation is in this class,
[42] Fix | Delete
# some in the modules CGI::QueryExtension and CGI::HtmlExtension. See
[43] Fix | Delete
# CGI::Cookie for specific information on handling cookies, and cgi/session.rb
[44] Fix | Delete
# (CGI::Session) for information on sessions.
[45] Fix | Delete
#
[46] Fix | Delete
# For queries, CGI provides methods to get at environmental variables,
[47] Fix | Delete
# parameters, cookies, and multipart request data. For responses, CGI provides
[48] Fix | Delete
# methods for writing output and generating HTML.
[49] Fix | Delete
#
[50] Fix | Delete
# Read on for more details. Examples are provided at the bottom.
[51] Fix | Delete
#
[52] Fix | Delete
# == Queries
[53] Fix | Delete
#
[54] Fix | Delete
# The CGI class dynamically mixes in parameter and cookie-parsing
[55] Fix | Delete
# functionality, environmental variable access, and support for
[56] Fix | Delete
# parsing multipart requests (including uploaded files) from the
[57] Fix | Delete
# CGI::QueryExtension module.
[58] Fix | Delete
#
[59] Fix | Delete
# === Environmental Variables
[60] Fix | Delete
#
[61] Fix | Delete
# The standard CGI environmental variables are available as read-only
[62] Fix | Delete
# attributes of a CGI object. The following is a list of these variables:
[63] Fix | Delete
#
[64] Fix | Delete
#
[65] Fix | Delete
# AUTH_TYPE HTTP_HOST REMOTE_IDENT
[66] Fix | Delete
# CONTENT_LENGTH HTTP_NEGOTIATE REMOTE_USER
[67] Fix | Delete
# CONTENT_TYPE HTTP_PRAGMA REQUEST_METHOD
[68] Fix | Delete
# GATEWAY_INTERFACE HTTP_REFERER SCRIPT_NAME
[69] Fix | Delete
# HTTP_ACCEPT HTTP_USER_AGENT SERVER_NAME
[70] Fix | Delete
# HTTP_ACCEPT_CHARSET PATH_INFO SERVER_PORT
[71] Fix | Delete
# HTTP_ACCEPT_ENCODING PATH_TRANSLATED SERVER_PROTOCOL
[72] Fix | Delete
# HTTP_ACCEPT_LANGUAGE QUERY_STRING SERVER_SOFTWARE
[73] Fix | Delete
# HTTP_CACHE_CONTROL REMOTE_ADDR
[74] Fix | Delete
# HTTP_FROM REMOTE_HOST
[75] Fix | Delete
#
[76] Fix | Delete
#
[77] Fix | Delete
# For each of these variables, there is a corresponding attribute with the
[78] Fix | Delete
# same name, except all lower case and without a preceding HTTP_.
[79] Fix | Delete
# +content_length+ and +server_port+ are integers; the rest are strings.
[80] Fix | Delete
#
[81] Fix | Delete
# === Parameters
[82] Fix | Delete
#
[83] Fix | Delete
# The method #params() returns a hash of all parameters in the request as
[84] Fix | Delete
# name/value-list pairs, where the value-list is an Array of one or more
[85] Fix | Delete
# values. The CGI object itself also behaves as a hash of parameter names
[86] Fix | Delete
# to values, but only returns a single value (as a String) for each
[87] Fix | Delete
# parameter name.
[88] Fix | Delete
#
[89] Fix | Delete
# For instance, suppose the request contains the parameter
[90] Fix | Delete
# "favourite_colours" with the multiple values "blue" and "green". The
[91] Fix | Delete
# following behaviour would occur:
[92] Fix | Delete
#
[93] Fix | Delete
# cgi.params["favourite_colours"] # => ["blue", "green"]
[94] Fix | Delete
# cgi["favourite_colours"] # => "blue"
[95] Fix | Delete
#
[96] Fix | Delete
# If a parameter does not exist, the former method will return an empty
[97] Fix | Delete
# array, the latter an empty string. The simplest way to test for existence
[98] Fix | Delete
# of a parameter is by the #has_key? method.
[99] Fix | Delete
#
[100] Fix | Delete
# === Cookies
[101] Fix | Delete
#
[102] Fix | Delete
# HTTP Cookies are automatically parsed from the request. They are available
[103] Fix | Delete
# from the #cookies() accessor, which returns a hash from cookie name to
[104] Fix | Delete
# CGI::Cookie object.
[105] Fix | Delete
#
[106] Fix | Delete
# === Multipart requests
[107] Fix | Delete
#
[108] Fix | Delete
# If a request's method is POST and its content type is multipart/form-data,
[109] Fix | Delete
# then it may contain uploaded files. These are stored by the QueryExtension
[110] Fix | Delete
# module in the parameters of the request. The parameter name is the name
[111] Fix | Delete
# attribute of the file input field, as usual. However, the value is not
[112] Fix | Delete
# a string, but an IO object, either an IOString for small files, or a
[113] Fix | Delete
# Tempfile for larger ones. This object also has the additional singleton
[114] Fix | Delete
# methods:
[115] Fix | Delete
#
[116] Fix | Delete
# #local_path():: the path of the uploaded file on the local filesystem
[117] Fix | Delete
# #original_filename():: the name of the file on the client computer
[118] Fix | Delete
# #content_type():: the content type of the file
[119] Fix | Delete
#
[120] Fix | Delete
# == Responses
[121] Fix | Delete
#
[122] Fix | Delete
# The CGI class provides methods for sending header and content output to
[123] Fix | Delete
# the HTTP client, and mixes in methods for programmatic HTML generation
[124] Fix | Delete
# from CGI::HtmlExtension and CGI::TagMaker modules. The precise version of HTML
[125] Fix | Delete
# to use for HTML generation is specified at object creation time.
[126] Fix | Delete
#
[127] Fix | Delete
# === Writing output
[128] Fix | Delete
#
[129] Fix | Delete
# The simplest way to send output to the HTTP client is using the #out() method.
[130] Fix | Delete
# This takes the HTTP headers as a hash parameter, and the body content
[131] Fix | Delete
# via a block. The headers can be generated as a string using the #header()
[132] Fix | Delete
# method. The output stream can be written directly to using the #print()
[133] Fix | Delete
# method.
[134] Fix | Delete
#
[135] Fix | Delete
# === Generating HTML
[136] Fix | Delete
#
[137] Fix | Delete
# Each HTML element has a corresponding method for generating that
[138] Fix | Delete
# element as a String. The name of this method is the same as that
[139] Fix | Delete
# of the element, all lowercase. The attributes of the element are
[140] Fix | Delete
# passed in as a hash, and the body as a no-argument block that evaluates
[141] Fix | Delete
# to a String. The HTML generation module knows which elements are
[142] Fix | Delete
# always empty, and silently drops any passed-in body. It also knows
[143] Fix | Delete
# which elements require matching closing tags and which don't. However,
[144] Fix | Delete
# it does not know what attributes are legal for which elements.
[145] Fix | Delete
#
[146] Fix | Delete
# There are also some additional HTML generation methods mixed in from
[147] Fix | Delete
# the CGI::HtmlExtension module. These include individual methods for the
[148] Fix | Delete
# different types of form inputs, and methods for elements that commonly
[149] Fix | Delete
# take particular attributes where the attributes can be directly specified
[150] Fix | Delete
# as arguments, rather than via a hash.
[151] Fix | Delete
#
[152] Fix | Delete
# == Examples of use
[153] Fix | Delete
#
[154] Fix | Delete
# === Get form values
[155] Fix | Delete
#
[156] Fix | Delete
# require "cgi"
[157] Fix | Delete
# cgi = CGI.new
[158] Fix | Delete
# value = cgi['field_name'] # <== value string for 'field_name'
[159] Fix | Delete
# # if not 'field_name' included, then return "".
[160] Fix | Delete
# fields = cgi.keys # <== array of field names
[161] Fix | Delete
#
[162] Fix | Delete
# # returns true if form has 'field_name'
[163] Fix | Delete
# cgi.has_key?('field_name')
[164] Fix | Delete
# cgi.has_key?('field_name')
[165] Fix | Delete
# cgi.include?('field_name')
[166] Fix | Delete
#
[167] Fix | Delete
# CAUTION! cgi['field_name'] returned an Array with the old
[168] Fix | Delete
# cgi.rb(included in ruby 1.6)
[169] Fix | Delete
#
[170] Fix | Delete
# === Get form values as hash
[171] Fix | Delete
#
[172] Fix | Delete
# require "cgi"
[173] Fix | Delete
# cgi = CGI.new
[174] Fix | Delete
# params = cgi.params
[175] Fix | Delete
#
[176] Fix | Delete
# cgi.params is a hash.
[177] Fix | Delete
#
[178] Fix | Delete
# cgi.params['new_field_name'] = ["value"] # add new param
[179] Fix | Delete
# cgi.params['field_name'] = ["new_value"] # change value
[180] Fix | Delete
# cgi.params.delete('field_name') # delete param
[181] Fix | Delete
# cgi.params.clear # delete all params
[182] Fix | Delete
#
[183] Fix | Delete
#
[184] Fix | Delete
# === Save form values to file
[185] Fix | Delete
#
[186] Fix | Delete
# require "pstore"
[187] Fix | Delete
# db = PStore.new("query.db")
[188] Fix | Delete
# db.transaction do
[189] Fix | Delete
# db["params"] = cgi.params
[190] Fix | Delete
# end
[191] Fix | Delete
#
[192] Fix | Delete
#
[193] Fix | Delete
# === Restore form values from file
[194] Fix | Delete
#
[195] Fix | Delete
# require "pstore"
[196] Fix | Delete
# db = PStore.new("query.db")
[197] Fix | Delete
# db.transaction do
[198] Fix | Delete
# cgi.params = db["params"]
[199] Fix | Delete
# end
[200] Fix | Delete
#
[201] Fix | Delete
#
[202] Fix | Delete
# === Get multipart form values
[203] Fix | Delete
#
[204] Fix | Delete
# require "cgi"
[205] Fix | Delete
# cgi = CGI.new
[206] Fix | Delete
# value = cgi['field_name'] # <== value string for 'field_name'
[207] Fix | Delete
# value.read # <== body of value
[208] Fix | Delete
# value.local_path # <== path to local file of value
[209] Fix | Delete
# value.original_filename # <== original filename of value
[210] Fix | Delete
# value.content_type # <== content_type of value
[211] Fix | Delete
#
[212] Fix | Delete
# and value has StringIO or Tempfile class methods.
[213] Fix | Delete
#
[214] Fix | Delete
# === Get cookie values
[215] Fix | Delete
#
[216] Fix | Delete
# require "cgi"
[217] Fix | Delete
# cgi = CGI.new
[218] Fix | Delete
# values = cgi.cookies['name'] # <== array of 'name'
[219] Fix | Delete
# # if not 'name' included, then return [].
[220] Fix | Delete
# names = cgi.cookies.keys # <== array of cookie names
[221] Fix | Delete
#
[222] Fix | Delete
# and cgi.cookies is a hash.
[223] Fix | Delete
#
[224] Fix | Delete
# === Get cookie objects
[225] Fix | Delete
#
[226] Fix | Delete
# require "cgi"
[227] Fix | Delete
# cgi = CGI.new
[228] Fix | Delete
# for name, cookie in cgi.cookies
[229] Fix | Delete
# cookie.expires = Time.now + 30
[230] Fix | Delete
# end
[231] Fix | Delete
# cgi.out("cookie" => cgi.cookies) {"string"}
[232] Fix | Delete
#
[233] Fix | Delete
# cgi.cookies # { "name1" => cookie1, "name2" => cookie2, ... }
[234] Fix | Delete
#
[235] Fix | Delete
# require "cgi"
[236] Fix | Delete
# cgi = CGI.new
[237] Fix | Delete
# cgi.cookies['name'].expires = Time.now + 30
[238] Fix | Delete
# cgi.out("cookie" => cgi.cookies['name']) {"string"}
[239] Fix | Delete
#
[240] Fix | Delete
# === Print http header and html string to $DEFAULT_OUTPUT ($>)
[241] Fix | Delete
#
[242] Fix | Delete
# require "cgi"
[243] Fix | Delete
# cgi = CGI.new("html3") # add HTML generation methods
[244] Fix | Delete
# cgi.out() do
[245] Fix | Delete
# cgi.html() do
[246] Fix | Delete
# cgi.head{ cgi.title{"TITLE"} } +
[247] Fix | Delete
# cgi.body() do
[248] Fix | Delete
# cgi.form() do
[249] Fix | Delete
# cgi.textarea("get_text") +
[250] Fix | Delete
# cgi.br +
[251] Fix | Delete
# cgi.submit
[252] Fix | Delete
# end +
[253] Fix | Delete
# cgi.pre() do
[254] Fix | Delete
# CGI::escapeHTML(
[255] Fix | Delete
# "params: " + cgi.params.inspect + "\n" +
[256] Fix | Delete
# "cookies: " + cgi.cookies.inspect + "\n" +
[257] Fix | Delete
# ENV.collect() do |key, value|
[258] Fix | Delete
# key + " --> " + value + "\n"
[259] Fix | Delete
# end.join("")
[260] Fix | Delete
# )
[261] Fix | Delete
# end
[262] Fix | Delete
# end
[263] Fix | Delete
# end
[264] Fix | Delete
# end
[265] Fix | Delete
#
[266] Fix | Delete
# # add HTML generation methods
[267] Fix | Delete
# CGI.new("html3") # html3.2
[268] Fix | Delete
# CGI.new("html4") # html4.01 (Strict)
[269] Fix | Delete
# CGI.new("html4Tr") # html4.01 Transitional
[270] Fix | Delete
# CGI.new("html4Fr") # html4.01 Frameset
[271] Fix | Delete
#
[272] Fix | Delete
class CGI
[273] Fix | Delete
[274] Fix | Delete
# :stopdoc:
[275] Fix | Delete
[276] Fix | Delete
# String for carriage return
[277] Fix | Delete
CR = "\015"
[278] Fix | Delete
[279] Fix | Delete
# String for linefeed
[280] Fix | Delete
LF = "\012"
[281] Fix | Delete
[282] Fix | Delete
# Standard internet newline sequence
[283] Fix | Delete
EOL = CR + LF
[284] Fix | Delete
[285] Fix | Delete
REVISION = '$Id: cgi.rb 26086 2009-12-14 02:40:07Z shyouhei $' #:nodoc:
[286] Fix | Delete
[287] Fix | Delete
NEEDS_BINMODE = true if /WIN/ni.match(RUBY_PLATFORM)
[288] Fix | Delete
[289] Fix | Delete
# Path separators in different environments.
[290] Fix | Delete
PATH_SEPARATOR = {'UNIX'=>'/', 'WINDOWS'=>'\\', 'MACINTOSH'=>':'}
[291] Fix | Delete
[292] Fix | Delete
# HTTP status codes.
[293] Fix | Delete
HTTP_STATUS = {
[294] Fix | Delete
"OK" => "200 OK",
[295] Fix | Delete
"PARTIAL_CONTENT" => "206 Partial Content",
[296] Fix | Delete
"MULTIPLE_CHOICES" => "300 Multiple Choices",
[297] Fix | Delete
"MOVED" => "301 Moved Permanently",
[298] Fix | Delete
"REDIRECT" => "302 Found",
[299] Fix | Delete
"NOT_MODIFIED" => "304 Not Modified",
[300] Fix | Delete
"BAD_REQUEST" => "400 Bad Request",
[301] Fix | Delete
"AUTH_REQUIRED" => "401 Authorization Required",
[302] Fix | Delete
"FORBIDDEN" => "403 Forbidden",
[303] Fix | Delete
"NOT_FOUND" => "404 Not Found",
[304] Fix | Delete
"METHOD_NOT_ALLOWED" => "405 Method Not Allowed",
[305] Fix | Delete
"NOT_ACCEPTABLE" => "406 Not Acceptable",
[306] Fix | Delete
"LENGTH_REQUIRED" => "411 Length Required",
[307] Fix | Delete
"PRECONDITION_FAILED" => "412 Precondition Failed",
[308] Fix | Delete
"SERVER_ERROR" => "500 Internal Server Error",
[309] Fix | Delete
"NOT_IMPLEMENTED" => "501 Method Not Implemented",
[310] Fix | Delete
"BAD_GATEWAY" => "502 Bad Gateway",
[311] Fix | Delete
"VARIANT_ALSO_VARIES" => "506 Variant Also Negotiates"
[312] Fix | Delete
}
[313] Fix | Delete
[314] Fix | Delete
# Abbreviated day-of-week names specified by RFC 822
[315] Fix | Delete
RFC822_DAYS = %w[ Sun Mon Tue Wed Thu Fri Sat ]
[316] Fix | Delete
[317] Fix | Delete
# Abbreviated month names specified by RFC 822
[318] Fix | Delete
RFC822_MONTHS = %w[ Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ]
[319] Fix | Delete
[320] Fix | Delete
# :startdoc:
[321] Fix | Delete
[322] Fix | Delete
def env_table
[323] Fix | Delete
ENV
[324] Fix | Delete
end
[325] Fix | Delete
[326] Fix | Delete
def stdinput
[327] Fix | Delete
$stdin
[328] Fix | Delete
end
[329] Fix | Delete
[330] Fix | Delete
def stdoutput
[331] Fix | Delete
$DEFAULT_OUTPUT
[332] Fix | Delete
end
[333] Fix | Delete
[334] Fix | Delete
private :env_table, :stdinput, :stdoutput
[335] Fix | Delete
[336] Fix | Delete
# URL-encode a string.
[337] Fix | Delete
# url_encoded_string = CGI::escape("'Stop!' said Fred")
[338] Fix | Delete
# # => "%27Stop%21%27+said+Fred"
[339] Fix | Delete
def CGI::escape(string)
[340] Fix | Delete
string.gsub(/([^ a-zA-Z0-9_.-]+)/n) do
[341] Fix | Delete
'%' + $1.unpack('H2' * $1.size).join('%').upcase
[342] Fix | Delete
end.tr(' ', '+')
[343] Fix | Delete
end
[344] Fix | Delete
[345] Fix | Delete
[346] Fix | Delete
# URL-decode a string.
[347] Fix | Delete
# string = CGI::unescape("%27Stop%21%27+said+Fred")
[348] Fix | Delete
# # => "'Stop!' said Fred"
[349] Fix | Delete
def CGI::unescape(string)
[350] Fix | Delete
string.tr('+', ' ').gsub(/((?:%[0-9a-fA-F]{2})+)/n) do
[351] Fix | Delete
[$1.delete('%')].pack('H*')
[352] Fix | Delete
end
[353] Fix | Delete
end
[354] Fix | Delete
[355] Fix | Delete
[356] Fix | Delete
# Escape special characters in HTML, namely &\"<>
[357] Fix | Delete
# CGI::escapeHTML('Usage: foo "bar" <baz>')
[358] Fix | Delete
# # => "Usage: foo &quot;bar&quot; &lt;baz&gt;"
[359] Fix | Delete
def CGI::escapeHTML(string)
[360] Fix | Delete
string.gsub(/&/n, '&amp;').gsub(/\"/n, '&quot;').gsub(/>/n, '&gt;').gsub(/</n, '&lt;')
[361] Fix | Delete
end
[362] Fix | Delete
[363] Fix | Delete
[364] Fix | Delete
# Unescape a string that has been HTML-escaped
[365] Fix | Delete
# CGI::unescapeHTML("Usage: foo &quot;bar&quot; &lt;baz&gt;")
[366] Fix | Delete
# # => "Usage: foo \"bar\" <baz>"
[367] Fix | Delete
def CGI::unescapeHTML(string)
[368] Fix | Delete
string.gsub(/&(amp|quot|gt|lt|\#[0-9]+|\#x[0-9A-Fa-f]+);/n) do
[369] Fix | Delete
match = $1.dup
[370] Fix | Delete
case match
[371] Fix | Delete
when 'amp' then '&'
[372] Fix | Delete
when 'quot' then '"'
[373] Fix | Delete
when 'gt' then '>'
[374] Fix | Delete
when 'lt' then '<'
[375] Fix | Delete
when /\A#0*(\d+)\z/n then
[376] Fix | Delete
if Integer($1) < 256
[377] Fix | Delete
Integer($1).chr
[378] Fix | Delete
else
[379] Fix | Delete
if Integer($1) < 65536 and ($KCODE[0] == ?u or $KCODE[0] == ?U)
[380] Fix | Delete
[Integer($1)].pack("U")
[381] Fix | Delete
else
[382] Fix | Delete
"&##{$1};"
[383] Fix | Delete
end
[384] Fix | Delete
end
[385] Fix | Delete
when /\A#x([0-9a-f]+)\z/ni then
[386] Fix | Delete
if $1.hex < 128
[387] Fix | Delete
$1.hex.chr
[388] Fix | Delete
else
[389] Fix | Delete
if $1.hex < 65536 and ($KCODE[0] == ?u or $KCODE[0] == ?U)
[390] Fix | Delete
[$1.hex].pack("U")
[391] Fix | Delete
else
[392] Fix | Delete
"&#x#{$1};"
[393] Fix | Delete
end
[394] Fix | Delete
end
[395] Fix | Delete
else
[396] Fix | Delete
"&#{match};"
[397] Fix | Delete
end
[398] Fix | Delete
end
[399] Fix | Delete
end
[400] Fix | Delete
[401] Fix | Delete
[402] Fix | Delete
# Escape only the tags of certain HTML elements in +string+.
[403] Fix | Delete
#
[404] Fix | Delete
# Takes an element or elements or array of elements. Each element
[405] Fix | Delete
# is specified by the name of the element, without angle brackets.
[406] Fix | Delete
# This matches both the start and the end tag of that element.
[407] Fix | Delete
# The attribute list of the open tag will also be escaped (for
[408] Fix | Delete
# instance, the double-quotes surrounding attribute values).
[409] Fix | Delete
#
[410] Fix | Delete
# print CGI::escapeElement('<BR><A HREF="url"></A>', "A", "IMG")
[411] Fix | Delete
# # "<BR>&lt;A HREF=&quot;url&quot;&gt;&lt;/A&gt"
[412] Fix | Delete
#
[413] Fix | Delete
# print CGI::escapeElement('<BR><A HREF="url"></A>', ["A", "IMG"])
[414] Fix | Delete
# # "<BR>&lt;A HREF=&quot;url&quot;&gt;&lt;/A&gt"
[415] Fix | Delete
def CGI::escapeElement(string, *elements)
[416] Fix | Delete
elements = elements[0] if elements[0].kind_of?(Array)
[417] Fix | Delete
unless elements.empty?
[418] Fix | Delete
string.gsub(/<\/?(?:#{elements.join("|")})(?!\w)(?:.|\n)*?>/ni) do
[419] Fix | Delete
CGI::escapeHTML($&)
[420] Fix | Delete
end
[421] Fix | Delete
else
[422] Fix | Delete
string
[423] Fix | Delete
end
[424] Fix | Delete
end
[425] Fix | Delete
[426] Fix | Delete
[427] Fix | Delete
# Undo escaping such as that done by CGI::escapeElement()
[428] Fix | Delete
#
[429] Fix | Delete
# print CGI::unescapeElement(
[430] Fix | Delete
# CGI::escapeHTML('<BR><A HREF="url"></A>'), "A", "IMG")
[431] Fix | Delete
# # "&lt;BR&gt;<A HREF="url"></A>"
[432] Fix | Delete
#
[433] Fix | Delete
# print CGI::unescapeElement(
[434] Fix | Delete
# CGI::escapeHTML('<BR><A HREF="url"></A>'), ["A", "IMG"])
[435] Fix | Delete
# # "&lt;BR&gt;<A HREF="url"></A>"
[436] Fix | Delete
def CGI::unescapeElement(string, *elements)
[437] Fix | Delete
elements = elements[0] if elements[0].kind_of?(Array)
[438] Fix | Delete
unless elements.empty?
[439] Fix | Delete
string.gsub(/&lt;\/?(?:#{elements.join("|")})(?!\w)(?:.|\n)*?&gt;/ni) do
[440] Fix | Delete
CGI::unescapeHTML($&)
[441] Fix | Delete
end
[442] Fix | Delete
else
[443] Fix | Delete
string
[444] Fix | Delete
end
[445] Fix | Delete
end
[446] Fix | Delete
[447] Fix | Delete
[448] Fix | Delete
# Format a +Time+ object as a String using the format specified by RFC 1123.
[449] Fix | Delete
#
[450] Fix | Delete
# CGI::rfc1123_date(Time.now)
[451] Fix | Delete
# # Sat, 01 Jan 2000 00:00:00 GMT
[452] Fix | Delete
def CGI::rfc1123_date(time)
[453] Fix | Delete
t = time.clone.gmtime
[454] Fix | Delete
return format("%s, %.2d %s %.4d %.2d:%.2d:%.2d GMT",
[455] Fix | Delete
RFC822_DAYS[t.wday], t.day, RFC822_MONTHS[t.month-1], t.year,
[456] Fix | Delete
t.hour, t.min, t.sec)
[457] Fix | Delete
end
[458] Fix | Delete
[459] Fix | Delete
[460] Fix | Delete
# Create an HTTP header block as a string.
[461] Fix | Delete
#
[462] Fix | Delete
# Includes the empty line that ends the header block.
[463] Fix | Delete
#
[464] Fix | Delete
# +options+ can be a string specifying the Content-Type (defaults
[465] Fix | Delete
# to text/html), or a hash of header key/value pairs. The following
[466] Fix | Delete
# header keys are recognized:
[467] Fix | Delete
#
[468] Fix | Delete
# type:: the Content-Type header. Defaults to "text/html"
[469] Fix | Delete
# charset:: the charset of the body, appended to the Content-Type header.
[470] Fix | Delete
# nph:: a boolean value. If true, prepend protocol string and status code, and
[471] Fix | Delete
# date; and sets default values for "server" and "connection" if not
[472] Fix | Delete
# explicitly set.
[473] Fix | Delete
# status:: the HTTP status code, returned as the Status header. See the
[474] Fix | Delete
# list of available status codes below.
[475] Fix | Delete
# server:: the server software, returned as the Server header.
[476] Fix | Delete
# connection:: the connection type, returned as the Connection header (for
[477] Fix | Delete
# instance, "close".
[478] Fix | Delete
# length:: the length of the content that will be sent, returned as the
[479] Fix | Delete
# Content-Length header.
[480] Fix | Delete
# language:: the language of the content, returned as the Content-Language
[481] Fix | Delete
# header.
[482] Fix | Delete
# expires:: the time on which the current content expires, as a +Time+
[483] Fix | Delete
# object, returned as the Expires header.
[484] Fix | Delete
# cookie:: a cookie or cookies, returned as one or more Set-Cookie headers.
[485] Fix | Delete
# The value can be the literal string of the cookie; a CGI::Cookie
[486] Fix | Delete
# object; an Array of literal cookie strings or Cookie objects; or a
[487] Fix | Delete
# hash all of whose values are literal cookie strings or Cookie objects.
[488] Fix | Delete
# These cookies are in addition to the cookies held in the
[489] Fix | Delete
# @output_cookies field.
[490] Fix | Delete
#
[491] Fix | Delete
# Other header lines can also be set; they are appended as key: value.
[492] Fix | Delete
#
[493] Fix | Delete
# header
[494] Fix | Delete
# # Content-Type: text/html
[495] Fix | Delete
#
[496] Fix | Delete
# header("text/plain")
[497] Fix | Delete
# # Content-Type: text/plain
[498] Fix | Delete
#
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function