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

{lib,test}/cgi: Specify frozen_string_literal: true.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
kazu 2017-02-18 05:52:16 +00:00
parent 3203ae53ff
commit fbd5cda6aa
15 changed files with 59 additions and 59 deletions

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
#
# cgi.rb - cgi support library
#

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
require 'cgi/util'
class CGI
# Class representing an HTTP cookie.
@ -143,7 +143,7 @@ class CGI
# Convert the Cookie to its string representation.
def to_s
val = collect{|v| CGI.escape(v) }.join("&")
buf = "#{@name}=#{val}"
buf = "#{@name}=#{val}".dup
buf << "; domain=#{@domain}" if @domain
buf << "; path=#{@path}" if @path
buf << "; expires=#{CGI::rfc1123_date(@expires)}" if @expires

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
#--
# Methods for generating HTML, parsing CGI-related parameters, and
# generating HTTP responses.
@ -182,7 +182,7 @@ class CGI
alias :header :http_header
def _header_for_string(content_type) #:nodoc:
buf = ''
buf = ''.dup
if nph?()
buf << "#{$CGI_ENV['SERVER_PROTOCOL'] || 'HTTP/1.0'} 200 OK#{EOL}"
buf << "Date: #{CGI.rfc1123_date(Time.now)}#{EOL}"
@ -198,7 +198,7 @@ class CGI
private :_header_for_string
def _header_for_hash(options) #:nodoc:
buf = ''
buf = ''.dup
## add charset to option['type']
options['type'] ||= 'text/html'
charset = options.delete('charset')
@ -480,7 +480,7 @@ class CGI
@files = {}
boundary_rexp = /--#{Regexp.quote(boundary)}(#{EOL}|--)/
boundary_size = "#{EOL}--#{boundary}#{EOL}".bytesize
buf = ''
buf = ''.dup
bufsize = 10 * 1024
max_count = MAX_MULTIPART_COUNT
n = 0
@ -535,12 +535,12 @@ class CGI
body.rewind
## original filename
/Content-Disposition:.* filename=(?:"(.*?)"|([^;\r\n]*))/i.match(head)
filename = $1 || $2 || ''
filename = $1 || $2 || ''.dup
filename = CGI.unescape(filename) if unescape_filename?()
body.instance_variable_set(:@original_filename, filename.taint)
## content type
/Content-Type: (.*)/i.match(head)
(content_type = $1 || '').chomp!
(content_type = $1 || ''.dup).chomp!
body.instance_variable_set(:@content_type, content_type.taint)
## query parameter name
/Content-Disposition:.* name=(?:"(.*?)"|([^;\r\n]*))/i.match(head)
@ -589,7 +589,7 @@ class CGI
else
begin
require 'stringio'
body = StringIO.new("".force_encoding(Encoding::ASCII_8BIT))
body = StringIO.new("".b)
rescue LoadError
require 'tempfile'
body = Tempfile.new('CGI', encoding: Encoding::ASCII_8BIT)
@ -700,7 +700,7 @@ class CGI
if value
return value
elsif defined? StringIO
StringIO.new("".force_encoding(Encoding::ASCII_8BIT))
StringIO.new("".b)
else
Tempfile.new("CGI",encoding: Encoding::ASCII_8BIT)
end

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
class CGI
# Base module for HTML-generation mixins.
#
@ -26,7 +26,7 @@ class CGI
# - O EMPTY
def nOE_element(element, attributes = {})
attributes={attributes=>nil} if attributes.kind_of?(String)
s = "<#{element.upcase}"
s = "<#{element.upcase}".dup
attributes.each do|name, value|
next unless value
s << " "
@ -408,7 +408,7 @@ class CGI
end
pretty = attributes.delete("PRETTY")
pretty = " " if true == pretty
buf = ""
buf = "".dup
if attributes.has_key?("DOCTYPE")
if attributes["DOCTYPE"]

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
#
# cgi/session.rb - session support for cgi scripts
#

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
#
# cgi/session/pstore.rb - persistent storage of marshalled session data
#

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
class CGI; module Util; end; extend Util; end
module CGI::Util
@@accept_charset="UTF-8" unless defined?(@@accept_charset)

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
require 'test/unit'
require 'cgi'
require 'stringio'
@ -15,7 +15,7 @@ class CGICookieTest < Test::Unit::TestCase
'REQUEST_METHOD' => 'GET',
'SCRIPT_NAME' => nil,
)
@str1="\xE3\x82\x86\xE3\x82\x93\xE3\x82\x86\xE3\x82\x93"
@str1="\xE3\x82\x86\xE3\x82\x93\xE3\x82\x86\xE3\x82\x93".dup
@str1.force_encoding("UTF-8") if defined?(::Encoding)
end
@ -39,7 +39,7 @@ class CGICookieTest < Test::Unit::TestCase
def test_cgi_cookie_new_complex
t = Time.gm(2030, 12, 31, 23, 59, 59)
value = ['val1', '&<>"', "\xA5\xE0\xA5\xB9\xA5\xAB"]
value = ['val1', '&<>"', "\xA5\xE0\xA5\xB9\xA5\xAB".dup]
value[2].force_encoding("EUC-JP") if defined?(::Encoding)
cookie = CGI::Cookie.new('name'=>'name1',
'value'=>value,

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
require 'test/unit'
require 'cgi'
require 'stringio'
@ -105,11 +105,11 @@ class CGICoreTest < Test::Unit::TestCase
hash={}
cgi = CGI.new(:accept_charset=>"UTF-8"){|key,val|hash[key]=val}
## cgi[]
assert_equal("\xBE\xBE\xB9\xBE".force_encoding("UTF-8"), cgi['str'])
assert_equal("\xBE\xBE\xB9\xBE".dup.force_encoding("UTF-8"), cgi['str'])
## cgi.params
assert_equal(["\xBE\xBE\xB9\xBE".force_encoding("UTF-8")], cgi.params['str'])
assert_equal(["\xBE\xBE\xB9\xBE".dup.force_encoding("UTF-8")], cgi.params['str'])
## accept-charset error
assert_equal({"str"=>"\xBE\xBE\xB9\xBE".force_encoding("UTF-8")},hash)
assert_equal({"str"=>"\xBE\xBE\xB9\xBE".dup.force_encoding("UTF-8")},hash)
$stdin.rewind
assert_raise(CGI::InvalidEncoding) do
@ -119,9 +119,9 @@ class CGICoreTest < Test::Unit::TestCase
$stdin.rewind
cgi = CGI.new(:accept_charset=>"EUC-JP")
## cgi[]
assert_equal("\xBE\xBE\xB9\xBE".force_encoding("EUC-JP"), cgi['str'])
assert_equal("\xBE\xBE\xB9\xBE".dup.force_encoding("EUC-JP"), cgi['str'])
## cgi.params
assert_equal(["\xBE\xBE\xB9\xBE".force_encoding("EUC-JP")], cgi.params['str'])
assert_equal(["\xBE\xBE\xB9\xBE".dup.force_encoding("EUC-JP")], cgi.params['str'])
else
assert(true)
end

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
require 'test/unit'
require 'cgi'
require 'time'
@ -58,7 +58,7 @@ class CGIHeaderTest < Test::Unit::TestCase
'expires' => Time.gm(2000, 1, 23, 12, 34, 56),
'location' => 'http://www.ruby-lang.org/',
}
expected = "Status: 302 Found\r\n"
expected = "Status: 302 Found\r\n".dup
expected << "Server: webrick\r\n"
expected << "Connection: close\r\n"
expected << "Content-Type: text/xhtml; charset=utf8\r\n"
@ -116,7 +116,7 @@ class CGIHeaderTest < Test::Unit::TestCase
CGI::Cookie.new('name'=>'name2', 'value'=>'value2', 'secure'=>true),
]
cgi.instance_variable_set('@output_cookies', cookies)
expected = "Content-Type: text/html; charset=utf8\r\n"
expected = "Content-Type: text/html; charset=utf8\r\n".dup
expected << "Set-Cookie: name1=abc&123; path=\r\n"
expected << "Set-Cookie: name2=value2; path=; secure\r\n"
expected << "\r\n"
@ -151,7 +151,7 @@ class CGIHeaderTest < Test::Unit::TestCase
actual.sub!(date, "Date: DATE_IS_REMOVED\r\n")
end
## assertion
expected = "HTTP/1.1 200 OK\r\n"
expected = "HTTP/1.1 200 OK\r\n".dup
expected << "Date: DATE_IS_REMOVED\r\n"
expected << "Server: Apache 2.2.0\r\n"
expected << "Connection: close\r\n"
@ -163,10 +163,10 @@ class CGIHeaderTest < Test::Unit::TestCase
expected.sub!(/^HTTP\/1.1 200 OK\r\n/, "HTTP/1.1 302 Found\r\n")
expected.sub!(/\r\n\r\n/, "\r\nlocation: http://www.example.com/\r\n\r\n")
assert_equal(expected, actual3)
expected = "Content-Type: text/html\r\n"
expected = "Content-Type: text/html\r\n".dup
expected << "\r\n"
assert_equal(expected, actual4)
expected = "Status: 302 Found\r\n"
expected = "Status: 302 Found\r\n".dup
expected << "Content-Type: text/html\r\n"
expected << "location: http://www.example.com/\r\n"
expected << "\r\n"

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
require 'test/unit'
require 'cgi'
require_relative 'update_env'

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
require 'test/unit'
require 'cgi'
require 'tempfile'
@ -33,7 +33,7 @@ class MultiPart
def initialize(boundary=nil)
@boundary = boundary || create_boundary()
@buf = ''
@buf = ''.dup
@buf.force_encoding(::Encoding::ASCII_8BIT) if defined?(::Encoding)
end
attr_reader :boundary
@ -53,7 +53,7 @@ class MultiPart
def close
buf = @buf
@buf = ''
@buf = ''.dup
return buf << "--#{boundary}--\r\n"
end
@ -202,7 +202,7 @@ class CGIMultipartTest < Test::Unit::TestCase
@boundary = '----WebKitFormBoundaryAAfvAII+YL9102cX'
@data = [
{:name=>'hidden1', :value=>'foobar'},
{:name=>'text1', :value=>"\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A"},
{:name=>'text1', :value=>"\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A".dup},
{:name=>'file1', :value=>_read('file1.html'),
:filename=>'file1.html', :content_type=>'text/html'},
{:name=>'image1', :value=>_read('small.png'),
@ -218,7 +218,7 @@ class CGIMultipartTest < Test::Unit::TestCase
@boundary = '----WebKitFormBoundaryAAfvAII+YL9102cX'
@data = [
{:name=>'hidden1', :value=>'foobar'},
{:name=>'text1', :value=>"\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A"},
{:name=>'text1', :value=>"\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A".dup},
{:name=>'file1', :value=>_read('file1.html'),
:filename=>'file1.html', :content_type=>'text/html'},
{:name=>'image1', :value=>_read('large.png'),
@ -323,7 +323,7 @@ class CGIMultipartTest < Test::Unit::TestCase
@boundary = '(.|\n)*'
@data = [
{:name=>'hidden1', :value=>'foobar'},
{:name=>'text1', :value=>"\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A"},
{:name=>'text1', :value=>"\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A".dup},
{:name=>'file1', :value=>_read('file1.html'),
:filename=>'file1.html', :content_type=>'text/html'},
{:name=>'image1', :value=>_read('small.png'),

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
require 'test/unit'
require 'cgi'
require 'cgi/session'
@ -30,7 +30,7 @@ class CGISessionTest < Test::Unit::TestCase
'SERVER_PROTOCOL' => 'HTTP/1.1',
)
value1="value1"
value2="\x8F\xBC\x8D]"
value2="\x8F\xBC\x8D]".dup
value2.force_encoding("SJIS") if defined?(::Encoding)
cgi = CGI.new
session = CGI::Session.new(cgi,"tmpdir"=>@session_dir)
@ -66,7 +66,7 @@ class CGISessionTest < Test::Unit::TestCase
'SERVER_PROTOCOL' => 'HTTP/1.1',
)
value1="value1"
value2="\x8F\xBC\x8D]"
value2="\x8F\xBC\x8D]".dup
value2.force_encoding("SJIS") if defined?(::Encoding)
cgi = CGI.new
session = CGI::Session.new(cgi,"tmpdir"=>@session_dir,"database_manager"=>CGI::Session::PStore)
@ -101,7 +101,7 @@ class CGISessionTest < Test::Unit::TestCase
'SERVER_PROTOCOL' => 'HTTP/1.1',
)
value1="value1"
value2="\x8F\xBC\x8D]"
value2="\x8F\xBC\x8D]".dup
value2.force_encoding("SJIS") if defined?(::Encoding)
cgi = CGI.new
session = CGI::Session.new(cgi,"tmpdir"=>@session_dir,"session_id"=>"foo")
@ -139,7 +139,7 @@ class CGISessionTest < Test::Unit::TestCase
'SERVER_PROTOCOL' => 'HTTP/1.1',
)
value1="value1"
value2="\x8F\xBC\x8D]"
value2="\x8F\xBC\x8D]".dup
value2.force_encoding("SJIS") if defined?(::Encoding)
cgi = CGI.new
session = CGI::Session.new(cgi,"tmpdir"=>@session_dir,"session_key"=>"bar")

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
require 'test/unit'
require 'cgi'
require 'stringio'

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
require 'test/unit'
require 'cgi'
require 'stringio'
@ -15,7 +15,7 @@ class CGIUtilTest < Test::Unit::TestCase
'REQUEST_METHOD' => 'GET',
'SCRIPT_NAME' => nil,
)
@str1="&<>\" \xE3\x82\x86\xE3\x82\x93\xE3\x82\x86\xE3\x82\x93"
@str1="&<>\" \xE3\x82\x86\xE3\x82\x93\xE3\x82\x86\xE3\x82\x93".dup
@str1.force_encoding("UTF-8") if defined?(::Encoding)
end
@ -31,14 +31,14 @@ class CGIUtilTest < Test::Unit::TestCase
def test_cgi_escape_with_invalid_byte_sequence
assert_nothing_raised(ArgumentError) do
assert_equal('%C0%3C%3C', CGI::escape("\xC0\<\<".force_encoding("UTF-8")))
assert_equal('%C0%3C%3C', CGI::escape("\xC0\<\<".dup.force_encoding("UTF-8")))
end
end
def test_cgi_escape_preserve_encoding
assert_equal(Encoding::US_ASCII, CGI::escape("\xC0\<\<".force_encoding("US-ASCII")).encoding)
assert_equal(Encoding::ASCII_8BIT, CGI::escape("\xC0\<\<".force_encoding("ASCII-8BIT")).encoding)
assert_equal(Encoding::UTF_8, CGI::escape("\xC0\<\<".force_encoding("UTF-8")).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::UTF_8, CGI::escape("\xC0\<\<".dup.force_encoding("UTF-8")).encoding)
end
def test_cgi_unescape
@ -51,9 +51,9 @@ class CGIUtilTest < Test::Unit::TestCase
end
def test_cgi_unescape_preserve_encoding
assert_equal(Encoding::US_ASCII, CGI::unescape("%C0%3C%3C".force_encoding("US-ASCII")).encoding)
assert_equal(Encoding::ASCII_8BIT, CGI::unescape("%C0%3C%3C".force_encoding("ASCII-8BIT")).encoding)
assert_equal(Encoding::UTF_8, CGI::unescape("%C0%3C%3C".force_encoding("UTF-8")).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::UTF_8, CGI::unescape("%C0%3C%3C".dup.force_encoding("UTF-8")).encoding)
end
def test_cgi_unescape_accept_charset
@ -72,7 +72,7 @@ class CGIUtilTest < Test::Unit::TestCase
end
def test_cgi_escape_html_duplicated
orig = "Ruby".force_encoding("US-ASCII")
orig = "Ruby".dup.force_encoding("US-ASCII")
str = CGI::escapeHTML(orig)
assert_equal(orig, str)
assert_not_same(orig, str)
@ -90,10 +90,10 @@ class CGIUtilTest < Test::Unit::TestCase
end
def test_cgi_escape_html_preserve_tainted
assert_not_predicate CGI::escapeHTML("'&\"><"), :tainted?
assert_predicate CGI::escapeHTML("'&\"><".taint), :tainted?
assert_not_predicate CGI::escapeHTML("Ruby"), :tainted?
assert_predicate CGI::escapeHTML("Ruby".taint), :tainted?
assert_not_predicate CGI::escapeHTML("'&\"><"), :tainted?
assert_predicate CGI::escapeHTML("'&\"><".dup.taint), :tainted?
assert_not_predicate CGI::escapeHTML("Ruby"), :tainted?
assert_predicate CGI::escapeHTML("Ruby".dup.taint), :tainted?
end
def test_cgi_escape_html_dont_freeze