1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

change call CGI methods from :: to .

Closes: https://github.com/ruby/ruby/pull/1749
This commit is contained in:
Semyon Pupkov 2017-11-13 14:48:29 +05:00 committed by Hiroshi SHIBATA
parent 8e7df4bbf9
commit 4173258fd0
No known key found for this signature in database
GPG key ID: F9CF13417264FAC2
7 changed files with 62 additions and 62 deletions

View file

@ -253,7 +253,7 @@
# end # end
# end + # end +
# cgi.pre do # cgi.pre do
# CGI::escapeHTML( # CGI.escapeHTML(
# "params: #{cgi.params.inspect}\n" + # "params: #{cgi.params.inspect}\n" +
# "cookies: #{cgi.cookies.inspect}\n" + # "cookies: #{cgi.cookies.inspect}\n" +
# ENV.collect do |key, value| # ENV.collect do |key, value|

View file

@ -146,7 +146,7 @@ class CGI
buf = "#{@name}=#{val}".dup buf = "#{@name}=#{val}".dup
buf << "; domain=#{@domain}" if @domain buf << "; domain=#{@domain}" if @domain
buf << "; path=#{@path}" if @path buf << "; path=#{@path}" if @path
buf << "; expires=#{CGI::rfc1123_date(@expires)}" if @expires buf << "; expires=#{CGI.rfc1123_date(@expires)}" if @expires
buf << "; secure" if @secure buf << "; secure" if @secure
buf << "; HttpOnly" if @httponly buf << "; HttpOnly" if @httponly
buf buf

View file

@ -375,14 +375,14 @@ class CGI
# Parse an HTTP query string into a hash of key=>value pairs. # Parse an HTTP query string into a hash of key=>value pairs.
# #
# params = CGI::parse("query_string") # params = CGI.parse("query_string")
# # {"name1" => ["value1", "value2", ...], # # {"name1" => ["value1", "value2", ...],
# # "name2" => ["value1", "value2", ...], ... } # # "name2" => ["value1", "value2", ...], ... }
# #
def CGI::parse(query) def self.parse(query)
params = {} params = {}
query.split(/[&;]/).each do |pairs| query.split(/[&;]/).each do |pairs|
key, value = pairs.split('=',2).collect{|v| CGI::unescape(v) } key, value = pairs.split('=',2).collect{|v| CGI.unescape(v) }
next unless key next unless key
@ -656,7 +656,7 @@ class CGI
@params = read_multipart(boundary, Integer(env_table['CONTENT_LENGTH'])) @params = read_multipart(boundary, Integer(env_table['CONTENT_LENGTH']))
else else
@multipart = false @multipart = false
@params = CGI::parse( @params = CGI.parse(
case env_table['REQUEST_METHOD'] case env_table['REQUEST_METHOD']
when "GET", "HEAD" when "GET", "HEAD"
if defined?(MOD_RUBY) if defined?(MOD_RUBY)
@ -686,7 +686,7 @@ class CGI
end end
end end
@cookies = CGI::Cookie::parse((env_table['HTTP_COOKIE'] or env_table['COOKIE'])) @cookies = CGI::Cookie.parse((env_table['HTTP_COOKIE'] or env_table['COOKIE']))
end end
private :initialize_query private :initialize_query

View file

@ -30,10 +30,10 @@ class CGI
attributes.each do|name, value| attributes.each do|name, value|
next unless value next unless value
s << " " s << " "
s << CGI::escapeHTML(name.to_s) s << CGI.escapeHTML(name.to_s)
if value != true if value != true
s << '="' s << '="'
s << CGI::escapeHTML(value.to_s) s << CGI.escapeHTML(value.to_s)
s << '"' s << '"'
end end
end end
@ -423,7 +423,7 @@ class CGI
buf << super(attributes) buf << super(attributes)
if pretty if pretty
CGI::pretty(buf, pretty) CGI.pretty(buf, pretty)
else else
buf buf
end end

View file

@ -403,7 +403,7 @@ class CGI
for line in f for line in f
line.chomp! line.chomp!
k, v = line.split('=',2) k, v = line.split('=',2)
@hash[CGI::unescape(k)] = Marshal.restore(CGI::unescape(v)) @hash[CGI.unescape(k)] = Marshal.restore(CGI.unescape(v))
end end
ensure ensure
f&.close f&.close
@ -421,7 +421,7 @@ class CGI
lockf.flock File::LOCK_EX lockf.flock File::LOCK_EX
f = File.open(@path+".new", File::CREAT|File::TRUNC|File::WRONLY, 0600) f = File.open(@path+".new", File::CREAT|File::TRUNC|File::WRONLY, 0600)
for k,v in @hash for k,v in @hash
f.printf "%s=%s\n", CGI::escape(k), CGI::escape(String(Marshal.dump(v))) f.printf "%s=%s\n", CGI.escape(k), CGI.escape(String(Marshal.dump(v)))
end end
f.close f.close
File.rename @path+".new", @path File.rename @path+".new", @path

View file

@ -7,7 +7,7 @@ end
module CGI::Util module CGI::Util
@@accept_charset="UTF-8" unless defined?(@@accept_charset) @@accept_charset="UTF-8" unless defined?(@@accept_charset)
# URL-encode a string. # URL-encode a string.
# url_encoded_string = CGI::escape("'Stop!' said Fred") # url_encoded_string = CGI.escape("'Stop!' said Fred")
# # => "%27Stop%21%27+said+Fred" # # => "%27Stop%21%27+said+Fred"
def escape(string) def escape(string)
encoding = string.encoding encoding = string.encoding
@ -17,7 +17,7 @@ module CGI::Util
end end
# URL-decode a string with encoding(optional). # URL-decode a string with encoding(optional).
# string = CGI::unescape("%27Stop%21%27+said+Fred") # string = CGI.unescape("%27Stop%21%27+said+Fred")
# # => "'Stop!' said Fred" # # => "'Stop!' said Fred"
def unescape(string,encoding=@@accept_charset) def unescape(string,encoding=@@accept_charset)
str=string.tr('+', ' ').b.gsub(/((?:%[0-9a-fA-F]{2})+)/) do |m| str=string.tr('+', ' ').b.gsub(/((?:%[0-9a-fA-F]{2})+)/) do |m|
@ -36,7 +36,7 @@ module CGI::Util
} }
# Escape special characters in HTML, namely '&\"<> # Escape special characters in HTML, namely '&\"<>
# CGI::escapeHTML('Usage: foo "bar" <baz>') # CGI.escapeHTML('Usage: foo "bar" <baz>')
# # => "Usage: foo &quot;bar&quot; &lt;baz&gt;" # # => "Usage: foo &quot;bar&quot; &lt;baz&gt;"
def escapeHTML(string) def escapeHTML(string)
enc = string.encoding enc = string.encoding
@ -60,7 +60,7 @@ module CGI::Util
end end
# Unescape a string that has been HTML-escaped # Unescape a string that has been HTML-escaped
# CGI::unescapeHTML("Usage: foo &quot;bar&quot; &lt;baz&gt;") # CGI.unescapeHTML("Usage: foo &quot;bar&quot; &lt;baz&gt;")
# # => "Usage: foo \"bar\" <baz>" # # => "Usage: foo \"bar\" <baz>"
def unescapeHTML(string) def unescapeHTML(string)
enc = string.encoding enc = string.encoding
@ -118,10 +118,10 @@ module CGI::Util
end end
end end
# Synonym for CGI::escapeHTML(str) # Synonym for CGI.escapeHTML(str)
alias escape_html escapeHTML alias escape_html escapeHTML
# Synonym for CGI::unescapeHTML(str) # Synonym for CGI.unescapeHTML(str)
alias unescape_html unescapeHTML alias unescape_html unescapeHTML
# Escape only the tags of certain HTML elements in +string+. # Escape only the tags of certain HTML elements in +string+.
@ -132,30 +132,30 @@ module CGI::Util
# The attribute list of the open tag will also be escaped (for # The attribute list of the open tag will also be escaped (for
# instance, the double-quotes surrounding attribute values). # instance, the double-quotes surrounding attribute values).
# #
# print CGI::escapeElement('<BR><A HREF="url"></A>', "A", "IMG") # print CGI.escapeElement('<BR><A HREF="url"></A>', "A", "IMG")
# # "<BR>&lt;A HREF=&quot;url&quot;&gt;&lt;/A&gt" # # "<BR>&lt;A HREF=&quot;url&quot;&gt;&lt;/A&gt"
# #
# print CGI::escapeElement('<BR><A HREF="url"></A>', ["A", "IMG"]) # print CGI.escapeElement('<BR><A HREF="url"></A>', ["A", "IMG"])
# # "<BR>&lt;A HREF=&quot;url&quot;&gt;&lt;/A&gt" # # "<BR>&lt;A HREF=&quot;url&quot;&gt;&lt;/A&gt"
def escapeElement(string, *elements) def escapeElement(string, *elements)
elements = elements[0] if elements[0].kind_of?(Array) elements = elements[0] if elements[0].kind_of?(Array)
unless elements.empty? unless elements.empty?
string.gsub(/<\/?(?:#{elements.join("|")})(?!\w)(?:.|\n)*?>/i) do string.gsub(/<\/?(?:#{elements.join("|")})(?!\w)(?:.|\n)*?>/i) do
CGI::escapeHTML($&) CGI.escapeHTML($&)
end end
else else
string string
end end
end end
# Undo escaping such as that done by CGI::escapeElement() # Undo escaping such as that done by CGI.escapeElement()
# #
# print CGI::unescapeElement( # print CGI.unescapeElement(
# CGI::escapeHTML('<BR><A HREF="url"></A>'), "A", "IMG") # CGI.escapeHTML('<BR><A HREF="url"></A>'), "A", "IMG")
# # "&lt;BR&gt;<A HREF="url"></A>" # # "&lt;BR&gt;<A HREF="url"></A>"
# #
# print CGI::unescapeElement( # print CGI.unescapeElement(
# CGI::escapeHTML('<BR><A HREF="url"></A>'), ["A", "IMG"]) # CGI.escapeHTML('<BR><A HREF="url"></A>'), ["A", "IMG"])
# # "&lt;BR&gt;<A HREF="url"></A>" # # "&lt;BR&gt;<A HREF="url"></A>"
def unescapeElement(string, *elements) def unescapeElement(string, *elements)
elements = elements[0] if elements[0].kind_of?(Array) elements = elements[0] if elements[0].kind_of?(Array)
@ -168,10 +168,10 @@ module CGI::Util
end end
end end
# Synonym for CGI::escapeElement(str) # Synonym for CGI.escapeElement(str)
alias escape_element escapeElement alias escape_element escapeElement
# Synonym for CGI::unescapeElement(str) # Synonym for CGI.unescapeElement(str)
alias unescape_element unescapeElement alias unescape_element unescapeElement
# Abbreviated day-of-week names specified by RFC 822 # Abbreviated day-of-week names specified by RFC 822
@ -182,7 +182,7 @@ module CGI::Util
# Format a +Time+ object as a String using the format specified by RFC 1123. # Format a +Time+ object as a String using the format specified by RFC 1123.
# #
# CGI::rfc1123_date(Time.now) # CGI.rfc1123_date(Time.now)
# # Sat, 01 Jan 2000 00:00:00 GMT # # Sat, 01 Jan 2000 00:00:00 GMT
def rfc1123_date(time) def rfc1123_date(time)
t = time.clone.gmtime t = time.clone.gmtime
@ -196,13 +196,13 @@ module CGI::Util
# +string+ is the HTML string to indent. +shift+ is the indentation # +string+ is the HTML string to indent. +shift+ is the indentation
# unit to use; it defaults to two spaces. # unit to use; it defaults to two spaces.
# #
# print CGI::pretty("<HTML><BODY></BODY></HTML>") # print CGI.pretty("<HTML><BODY></BODY></HTML>")
# # <HTML> # # <HTML>
# # <BODY> # # <BODY>
# # </BODY> # # </BODY>
# # </HTML> # # </HTML>
# #
# print CGI::pretty("<HTML><BODY></BODY></HTML>", "\t") # print CGI.pretty("<HTML><BODY></BODY></HTML>", "\t")
# # <HTML> # # <HTML>
# # <BODY> # # <BODY>
# # </BODY> # # </BODY>

View file

@ -25,30 +25,30 @@ class CGIUtilTest < Test::Unit::TestCase
def test_cgi_escape def test_cgi_escape
assert_equal('%26%3C%3E%22+%E3%82%86%E3%82%93%E3%82%86%E3%82%93', CGI::escape(@str1)) assert_equal('%26%3C%3E%22+%E3%82%86%E3%82%93%E3%82%86%E3%82%93', CGI.escape(@str1))
assert_equal('%26%3C%3E%22+%E3%82%86%E3%82%93%E3%82%86%E3%82%93'.ascii_only?, CGI::escape(@str1).ascii_only?) if defined?(::Encoding) assert_equal('%26%3C%3E%22+%E3%82%86%E3%82%93%E3%82%86%E3%82%93'.ascii_only?, CGI.escape(@str1).ascii_only?) if defined?(::Encoding)
end end
def test_cgi_escape_with_unreserved_characters def test_cgi_escape_with_unreserved_characters
assert_equal("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~", assert_equal("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~",
CGI::escape("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~"), CGI.escape("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~"),
"should not escape any unreserved characters, as per RFC3986 Section 2.3") "should not escape any unreserved characters, as per RFC3986 Section 2.3")
end end
def test_cgi_escape_with_invalid_byte_sequence def test_cgi_escape_with_invalid_byte_sequence
assert_nothing_raised(ArgumentError) do assert_nothing_raised(ArgumentError) do
assert_equal('%C0%3C%3C', CGI::escape("\xC0\<\<".dup.force_encoding("UTF-8"))) assert_equal('%C0%3C%3C', CGI.escape("\xC0\<\<".dup.force_encoding("UTF-8")))
end end
end end
def test_cgi_escape_preserve_encoding def test_cgi_escape_preserve_encoding
assert_equal(Encoding::US_ASCII, CGI::escape("\xC0\<\<".dup.force_encoding("US-ASCII")).encoding) assert_equal(Encoding::US_ASCII, CGI.escape("\xC0\<\<".dup.force_encoding("US-ASCII")).encoding)
assert_equal(Encoding::ASCII_8BIT, CGI::escape("\xC0\<\<".dup.force_encoding("ASCII-8BIT")).encoding) assert_equal(Encoding::ASCII_8BIT, CGI.escape("\xC0\<\<".dup.force_encoding("ASCII-8BIT")).encoding)
assert_equal(Encoding::UTF_8, CGI::escape("\xC0\<\<".dup.force_encoding("UTF-8")).encoding) assert_equal(Encoding::UTF_8, CGI.escape("\xC0\<\<".dup.force_encoding("UTF-8")).encoding)
end end
def test_cgi_unescape def test_cgi_unescape
str = CGI::unescape('%26%3C%3E%22+%E3%82%86%E3%82%93%E3%82%86%E3%82%93') str = CGI.unescape('%26%3C%3E%22+%E3%82%86%E3%82%93%E3%82%86%E3%82%93')
assert_equal(@str1, str) assert_equal(@str1, str)
return unless defined?(::Encoding) return unless defined?(::Encoding)
@ -57,9 +57,9 @@ class CGIUtilTest < Test::Unit::TestCase
end end
def test_cgi_unescape_preserve_encoding def test_cgi_unescape_preserve_encoding
assert_equal(Encoding::US_ASCII, CGI::unescape("%C0%3C%3C".dup.force_encoding("US-ASCII")).encoding) assert_equal(Encoding::US_ASCII, CGI.unescape("%C0%3C%3C".dup.force_encoding("US-ASCII")).encoding)
assert_equal(Encoding::ASCII_8BIT, CGI::unescape("%C0%3C%3C".dup.force_encoding("ASCII-8BIT")).encoding) assert_equal(Encoding::ASCII_8BIT, CGI.unescape("%C0%3C%3C".dup.force_encoding("ASCII-8BIT")).encoding)
assert_equal(Encoding::UTF_8, CGI::unescape("%C0%3C%3C".dup.force_encoding("UTF-8")).encoding) assert_equal(Encoding::UTF_8, CGI.unescape("%C0%3C%3C".dup.force_encoding("UTF-8")).encoding)
end end
def test_cgi_unescape_accept_charset def test_cgi_unescape_accept_charset
@ -73,23 +73,23 @@ class CGIUtilTest < Test::Unit::TestCase
end end
def test_cgi_pretty def test_cgi_pretty
assert_equal("<HTML>\n <BODY>\n </BODY>\n</HTML>\n",CGI::pretty("<HTML><BODY></BODY></HTML>")) assert_equal("<HTML>\n <BODY>\n </BODY>\n</HTML>\n",CGI.pretty("<HTML><BODY></BODY></HTML>"))
assert_equal("<HTML>\n\t<BODY>\n\t</BODY>\n</HTML>\n",CGI::pretty("<HTML><BODY></BODY></HTML>","\t")) assert_equal("<HTML>\n\t<BODY>\n\t</BODY>\n</HTML>\n",CGI.pretty("<HTML><BODY></BODY></HTML>","\t"))
end end
def test_cgi_escapeHTML def test_cgi_escapeHTML
assert_equal("&#39;&amp;&quot;&gt;&lt;", CGI::escapeHTML("'&\"><")) assert_equal("&#39;&amp;&quot;&gt;&lt;", CGI.escapeHTML("'&\"><"))
end end
def test_cgi_escape_html_duplicated def test_cgi_escape_html_duplicated
orig = "Ruby".dup.force_encoding("US-ASCII") orig = "Ruby".dup.force_encoding("US-ASCII")
str = CGI::escapeHTML(orig) str = CGI.escapeHTML(orig)
assert_equal(orig, str) assert_equal(orig, str)
assert_not_same(orig, str) assert_not_same(orig, str)
end end
def assert_cgi_escape_html_preserve_encoding(str, encoding) def assert_cgi_escape_html_preserve_encoding(str, encoding)
assert_equal(encoding, CGI::escapeHTML(str.dup.force_encoding(encoding)).encoding) assert_equal(encoding, CGI.escapeHTML(str.dup.force_encoding(encoding)).encoding)
end end
def test_cgi_escape_html_preserve_encoding def test_cgi_escape_html_preserve_encoding
@ -100,25 +100,25 @@ class CGIUtilTest < Test::Unit::TestCase
end end
def test_cgi_escape_html_preserve_tainted def test_cgi_escape_html_preserve_tainted
assert_not_predicate CGI::escapeHTML("'&\"><"), :tainted? assert_not_predicate CGI.escapeHTML("'&\"><"), :tainted?
assert_predicate CGI::escapeHTML("'&\"><".dup.taint), :tainted? assert_predicate CGI.escapeHTML("'&\"><".dup.taint), :tainted?
assert_not_predicate CGI::escapeHTML("Ruby"), :tainted? assert_not_predicate CGI.escapeHTML("Ruby"), :tainted?
assert_predicate CGI::escapeHTML("Ruby".dup.taint), :tainted? assert_predicate CGI.escapeHTML("Ruby".dup.taint), :tainted?
end end
def test_cgi_escape_html_dont_freeze def test_cgi_escape_html_dont_freeze
assert_not_predicate CGI::escapeHTML("'&\"><".dup), :frozen? assert_not_predicate CGI.escapeHTML("'&\"><".dup), :frozen?
assert_not_predicate CGI::escapeHTML("'&\"><".freeze), :frozen? assert_not_predicate CGI.escapeHTML("'&\"><".freeze), :frozen?
assert_not_predicate CGI::escapeHTML("Ruby".dup), :frozen? assert_not_predicate CGI.escapeHTML("Ruby".dup), :frozen?
assert_not_predicate CGI::escapeHTML("Ruby".freeze), :frozen? assert_not_predicate CGI.escapeHTML("Ruby".freeze), :frozen?
end end
def test_cgi_unescapeHTML def test_cgi_unescapeHTML
assert_equal("'&\"><", CGI::unescapeHTML("&#39;&amp;&quot;&gt;&lt;")) assert_equal("'&\"><", CGI.unescapeHTML("&#39;&amp;&quot;&gt;&lt;"))
end end
def test_cgi_unescapeHTML_invalid def test_cgi_unescapeHTML_invalid
assert_equal('&<&amp>&quot&abcdefghijklmn', CGI::unescapeHTML('&&lt;&amp&gt;&quot&abcdefghijklmn')) assert_equal('&<&amp>&quot&abcdefghijklmn', CGI.unescapeHTML('&&lt;&amp&gt;&quot&abcdefghijklmn'))
end end
Encoding.list.each do |enc| Encoding.list.each do |enc|
@ -129,10 +129,10 @@ class CGIUtilTest < Test::Unit::TestCase
next next
else else
define_method("test_cgi_escapeHTML:#{enc.name}") do define_method("test_cgi_escapeHTML:#{enc.name}") do
assert_equal(escaped, CGI::escapeHTML(unescaped)) assert_equal(escaped, CGI.escapeHTML(unescaped))
end end
define_method("test_cgi_unescapeHTML:#{enc.name}") do define_method("test_cgi_unescapeHTML:#{enc.name}") do
assert_equal(unescaped, CGI::unescapeHTML(escaped)) assert_equal(unescaped, CGI.unescapeHTML(escaped))
end end
end end
end end
@ -146,16 +146,16 @@ class CGIUtilTest < Test::Unit::TestCase
next next
else else
define_method("test_cgi_escape:#{enc.name}") do define_method("test_cgi_escape:#{enc.name}") do
assert_equal(escaped, CGI::escape(unescaped)) assert_equal(escaped, CGI.escape(unescaped))
end end
define_method("test_cgi_unescape:#{enc.name}") do define_method("test_cgi_unescape:#{enc.name}") do
assert_equal(unescaped, CGI::unescape(escaped, enc)) assert_equal(unescaped, CGI.unescape(escaped, enc))
end end
end end
end end
def test_cgi_unescapeHTML_uppercasecharacter def test_cgi_unescapeHTML_uppercasecharacter
assert_equal("\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86", CGI::unescapeHTML("&#x3042;&#x3044;&#X3046;")) assert_equal("\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86", CGI.unescapeHTML("&#x3042;&#x3044;&#X3046;"))
end end
def test_cgi_include_escape def test_cgi_include_escape