Skip to content

Commit

Permalink
{lib,test}/cgi: Specify frozen_string_literal: true.
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
znz committed Feb 18, 2017
1 parent 3203ae5 commit fbd5cda
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 59 deletions.
2 changes: 1 addition & 1 deletion lib/cgi.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
#
# cgi.rb - cgi support library
#
Expand Down
4 changes: 2 additions & 2 deletions lib/cgi/cookie.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
require 'cgi/util'
class CGI
# Class representing an HTTP cookie.
Expand Down Expand Up @@ -143,7 +143,7 @@ def httponly=(val)
# 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
Expand Down
16 changes: 8 additions & 8 deletions lib/cgi/core.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
#--
# Methods for generating HTML, parsing CGI-related parameters, and
# generating HTTP responses.
Expand Down Expand Up @@ -182,7 +182,7 @@ def http_header(options='text/html')
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}"
Expand All @@ -198,7 +198,7 @@ def _header_for_string(content_type) #:nodoc:
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')
Expand Down Expand Up @@ -480,7 +480,7 @@ def read_multipart(boundary, content_length)
@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
Expand Down Expand Up @@ -535,12 +535,12 @@ def local_path
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)
Expand Down Expand Up @@ -589,7 +589,7 @@ def create_body(is_large) #:nodoc:
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)
Expand Down Expand Up @@ -700,7 +700,7 @@ def [](key)
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
Expand Down
6 changes: 3 additions & 3 deletions lib/cgi/html.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
class CGI
# Base module for HTML-generation mixins.
#
Expand Down Expand Up @@ -26,7 +26,7 @@ def nn_element_def(attributes = {}, &block)
# - 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 << " "
Expand Down Expand Up @@ -408,7 +408,7 @@ def html(attributes = {}) # :yield:
end
pretty = attributes.delete("PRETTY")
pretty = " " if true == pretty
buf = ""
buf = "".dup

if attributes.has_key?("DOCTYPE")
if attributes["DOCTYPE"]
Expand Down
2 changes: 1 addition & 1 deletion lib/cgi/session.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
#
# cgi/session.rb - session support for cgi scripts
#
Expand Down
2 changes: 1 addition & 1 deletion lib/cgi/session/pstore.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
#
# cgi/session/pstore.rb - persistent storage of marshalled session data
#
Expand Down
2 changes: 1 addition & 1 deletion lib/cgi/util.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
6 changes: 3 additions & 3 deletions test/cgi/test_cgi_cookie.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
require 'test/unit'
require 'cgi'
require 'stringio'
Expand All @@ -15,7 +15,7 @@ def setup
'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

Expand All @@ -39,7 +39,7 @@ def test_cgi_cookie_new_simple

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,
Expand Down
12 changes: 6 additions & 6 deletions test/cgi/test_cgi_core.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
require 'test/unit'
require 'cgi'
require 'stringio'
Expand Down Expand Up @@ -105,11 +105,11 @@ def test_cgi_core_params_encoding_check
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
Expand All @@ -119,9 +119,9 @@ def test_cgi_core_params_encoding_check
$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
Expand Down
12 changes: 6 additions & 6 deletions test/cgi/test_cgi_header.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
require 'test/unit'
require 'cgi'
require 'time'
Expand Down Expand Up @@ -58,7 +58,7 @@ def test_cgi_http_header_complex
'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"
Expand Down Expand Up @@ -116,7 +116,7 @@ def test_cgi_http_header_output_cookies
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"
Expand Down Expand Up @@ -151,7 +151,7 @@ def test_cgi_http_header_nph
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"
Expand All @@ -163,10 +163,10 @@ def test_cgi_http_header_nph
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"
Expand Down
2 changes: 1 addition & 1 deletion test/cgi/test_cgi_modruby.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
require 'test/unit'
require 'cgi'
require_relative 'update_env'
Expand Down
12 changes: 6 additions & 6 deletions test/cgi/test_cgi_multipart.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
require 'test/unit'
require 'cgi'
require 'tempfile'
Expand Down Expand Up @@ -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
Expand All @@ -53,7 +53,7 @@ def append(name, value, filename=nil, content_type=nil)

def close
buf = @buf
@buf = ''
@buf = ''.dup
return buf << "--#{boundary}--\r\n"
end

Expand Down Expand Up @@ -202,7 +202,7 @@ def test_cgi_multipart_stringio
@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'),
Expand All @@ -218,7 +218,7 @@ def test_cgi_multipart_tempfile
@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'),
Expand Down Expand Up @@ -323,7 +323,7 @@ def test_cgi_multipart_quoteboundary ## [JVN#84798830]
@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'),
Expand Down
10 changes: 5 additions & 5 deletions test/cgi/test_cgi_session.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
require 'test/unit'
require 'cgi'
require 'cgi/session'
Expand Down Expand Up @@ -30,7 +30,7 @@ def test_cgi_session_filestore
'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)
Expand Down Expand Up @@ -66,7 +66,7 @@ def test_cgi_session_pstore
'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)
Expand Down Expand Up @@ -101,7 +101,7 @@ def test_cgi_session_specify_session_id
'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")
Expand Down Expand Up @@ -139,7 +139,7 @@ def test_cgi_session_specify_session_key
'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")
Expand Down
2 changes: 1 addition & 1 deletion test/cgi/test_cgi_tag_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
require 'test/unit'
require 'cgi'
require 'stringio'
Expand Down
Loading

0 comments on commit fbd5cda

Please sign in to comment.