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:
parent
3203ae53ff
commit
fbd5cda6aa
15 changed files with 59 additions and 59 deletions
|
@ -1,4 +1,4 @@
|
||||||
# frozen_string_literal: false
|
# frozen_string_literal: true
|
||||||
#
|
#
|
||||||
# cgi.rb - cgi support library
|
# cgi.rb - cgi support library
|
||||||
#
|
#
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# frozen_string_literal: false
|
# frozen_string_literal: true
|
||||||
require 'cgi/util'
|
require 'cgi/util'
|
||||||
class CGI
|
class CGI
|
||||||
# Class representing an HTTP cookie.
|
# Class representing an HTTP cookie.
|
||||||
|
@ -143,7 +143,7 @@ class CGI
|
||||||
# Convert the Cookie to its string representation.
|
# Convert the Cookie to its string representation.
|
||||||
def to_s
|
def to_s
|
||||||
val = collect{|v| CGI.escape(v) }.join("&")
|
val = collect{|v| CGI.escape(v) }.join("&")
|
||||||
buf = "#{@name}=#{val}"
|
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
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# frozen_string_literal: false
|
# frozen_string_literal: true
|
||||||
#--
|
#--
|
||||||
# Methods for generating HTML, parsing CGI-related parameters, and
|
# Methods for generating HTML, parsing CGI-related parameters, and
|
||||||
# generating HTTP responses.
|
# generating HTTP responses.
|
||||||
|
@ -182,7 +182,7 @@ class CGI
|
||||||
alias :header :http_header
|
alias :header :http_header
|
||||||
|
|
||||||
def _header_for_string(content_type) #:nodoc:
|
def _header_for_string(content_type) #:nodoc:
|
||||||
buf = ''
|
buf = ''.dup
|
||||||
if nph?()
|
if nph?()
|
||||||
buf << "#{$CGI_ENV['SERVER_PROTOCOL'] || 'HTTP/1.0'} 200 OK#{EOL}"
|
buf << "#{$CGI_ENV['SERVER_PROTOCOL'] || 'HTTP/1.0'} 200 OK#{EOL}"
|
||||||
buf << "Date: #{CGI.rfc1123_date(Time.now)}#{EOL}"
|
buf << "Date: #{CGI.rfc1123_date(Time.now)}#{EOL}"
|
||||||
|
@ -198,7 +198,7 @@ class CGI
|
||||||
private :_header_for_string
|
private :_header_for_string
|
||||||
|
|
||||||
def _header_for_hash(options) #:nodoc:
|
def _header_for_hash(options) #:nodoc:
|
||||||
buf = ''
|
buf = ''.dup
|
||||||
## add charset to option['type']
|
## add charset to option['type']
|
||||||
options['type'] ||= 'text/html'
|
options['type'] ||= 'text/html'
|
||||||
charset = options.delete('charset')
|
charset = options.delete('charset')
|
||||||
|
@ -480,7 +480,7 @@ class CGI
|
||||||
@files = {}
|
@files = {}
|
||||||
boundary_rexp = /--#{Regexp.quote(boundary)}(#{EOL}|--)/
|
boundary_rexp = /--#{Regexp.quote(boundary)}(#{EOL}|--)/
|
||||||
boundary_size = "#{EOL}--#{boundary}#{EOL}".bytesize
|
boundary_size = "#{EOL}--#{boundary}#{EOL}".bytesize
|
||||||
buf = ''
|
buf = ''.dup
|
||||||
bufsize = 10 * 1024
|
bufsize = 10 * 1024
|
||||||
max_count = MAX_MULTIPART_COUNT
|
max_count = MAX_MULTIPART_COUNT
|
||||||
n = 0
|
n = 0
|
||||||
|
@ -535,12 +535,12 @@ class CGI
|
||||||
body.rewind
|
body.rewind
|
||||||
## original filename
|
## original filename
|
||||||
/Content-Disposition:.* filename=(?:"(.*?)"|([^;\r\n]*))/i.match(head)
|
/Content-Disposition:.* filename=(?:"(.*?)"|([^;\r\n]*))/i.match(head)
|
||||||
filename = $1 || $2 || ''
|
filename = $1 || $2 || ''.dup
|
||||||
filename = CGI.unescape(filename) if unescape_filename?()
|
filename = CGI.unescape(filename) if unescape_filename?()
|
||||||
body.instance_variable_set(:@original_filename, filename.taint)
|
body.instance_variable_set(:@original_filename, filename.taint)
|
||||||
## content type
|
## content type
|
||||||
/Content-Type: (.*)/i.match(head)
|
/Content-Type: (.*)/i.match(head)
|
||||||
(content_type = $1 || '').chomp!
|
(content_type = $1 || ''.dup).chomp!
|
||||||
body.instance_variable_set(:@content_type, content_type.taint)
|
body.instance_variable_set(:@content_type, content_type.taint)
|
||||||
## query parameter name
|
## query parameter name
|
||||||
/Content-Disposition:.* name=(?:"(.*?)"|([^;\r\n]*))/i.match(head)
|
/Content-Disposition:.* name=(?:"(.*?)"|([^;\r\n]*))/i.match(head)
|
||||||
|
@ -589,7 +589,7 @@ class CGI
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
require 'stringio'
|
require 'stringio'
|
||||||
body = StringIO.new("".force_encoding(Encoding::ASCII_8BIT))
|
body = StringIO.new("".b)
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
require 'tempfile'
|
require 'tempfile'
|
||||||
body = Tempfile.new('CGI', encoding: Encoding::ASCII_8BIT)
|
body = Tempfile.new('CGI', encoding: Encoding::ASCII_8BIT)
|
||||||
|
@ -700,7 +700,7 @@ class CGI
|
||||||
if value
|
if value
|
||||||
return value
|
return value
|
||||||
elsif defined? StringIO
|
elsif defined? StringIO
|
||||||
StringIO.new("".force_encoding(Encoding::ASCII_8BIT))
|
StringIO.new("".b)
|
||||||
else
|
else
|
||||||
Tempfile.new("CGI",encoding: Encoding::ASCII_8BIT)
|
Tempfile.new("CGI",encoding: Encoding::ASCII_8BIT)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# frozen_string_literal: false
|
# frozen_string_literal: true
|
||||||
class CGI
|
class CGI
|
||||||
# Base module for HTML-generation mixins.
|
# Base module for HTML-generation mixins.
|
||||||
#
|
#
|
||||||
|
@ -26,7 +26,7 @@ class CGI
|
||||||
# - O EMPTY
|
# - O EMPTY
|
||||||
def nOE_element(element, attributes = {})
|
def nOE_element(element, attributes = {})
|
||||||
attributes={attributes=>nil} if attributes.kind_of?(String)
|
attributes={attributes=>nil} if attributes.kind_of?(String)
|
||||||
s = "<#{element.upcase}"
|
s = "<#{element.upcase}".dup
|
||||||
attributes.each do|name, value|
|
attributes.each do|name, value|
|
||||||
next unless value
|
next unless value
|
||||||
s << " "
|
s << " "
|
||||||
|
@ -408,7 +408,7 @@ class CGI
|
||||||
end
|
end
|
||||||
pretty = attributes.delete("PRETTY")
|
pretty = attributes.delete("PRETTY")
|
||||||
pretty = " " if true == pretty
|
pretty = " " if true == pretty
|
||||||
buf = ""
|
buf = "".dup
|
||||||
|
|
||||||
if attributes.has_key?("DOCTYPE")
|
if attributes.has_key?("DOCTYPE")
|
||||||
if attributes["DOCTYPE"]
|
if attributes["DOCTYPE"]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# frozen_string_literal: false
|
# frozen_string_literal: true
|
||||||
#
|
#
|
||||||
# cgi/session.rb - session support for cgi scripts
|
# cgi/session.rb - session support for cgi scripts
|
||||||
#
|
#
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# frozen_string_literal: false
|
# frozen_string_literal: true
|
||||||
#
|
#
|
||||||
# cgi/session/pstore.rb - persistent storage of marshalled session data
|
# cgi/session/pstore.rb - persistent storage of marshalled session data
|
||||||
#
|
#
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# frozen_string_literal: false
|
# frozen_string_literal: true
|
||||||
class CGI; module Util; end; extend Util; end
|
class CGI; module Util; end; extend Util; end
|
||||||
module CGI::Util
|
module CGI::Util
|
||||||
@@accept_charset="UTF-8" unless defined?(@@accept_charset)
|
@@accept_charset="UTF-8" unless defined?(@@accept_charset)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# frozen_string_literal: false
|
# frozen_string_literal: true
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
require 'cgi'
|
require 'cgi'
|
||||||
require 'stringio'
|
require 'stringio'
|
||||||
|
@ -15,7 +15,7 @@ class CGICookieTest < Test::Unit::TestCase
|
||||||
'REQUEST_METHOD' => 'GET',
|
'REQUEST_METHOD' => 'GET',
|
||||||
'SCRIPT_NAME' => nil,
|
'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)
|
@str1.force_encoding("UTF-8") if defined?(::Encoding)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ class CGICookieTest < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_cgi_cookie_new_complex
|
def test_cgi_cookie_new_complex
|
||||||
t = Time.gm(2030, 12, 31, 23, 59, 59)
|
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)
|
value[2].force_encoding("EUC-JP") if defined?(::Encoding)
|
||||||
cookie = CGI::Cookie.new('name'=>'name1',
|
cookie = CGI::Cookie.new('name'=>'name1',
|
||||||
'value'=>value,
|
'value'=>value,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# frozen_string_literal: false
|
# frozen_string_literal: true
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
require 'cgi'
|
require 'cgi'
|
||||||
require 'stringio'
|
require 'stringio'
|
||||||
|
@ -105,11 +105,11 @@ class CGICoreTest < Test::Unit::TestCase
|
||||||
hash={}
|
hash={}
|
||||||
cgi = CGI.new(:accept_charset=>"UTF-8"){|key,val|hash[key]=val}
|
cgi = CGI.new(:accept_charset=>"UTF-8"){|key,val|hash[key]=val}
|
||||||
## cgi[]
|
## 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
|
## 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
|
## 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
|
$stdin.rewind
|
||||||
assert_raise(CGI::InvalidEncoding) do
|
assert_raise(CGI::InvalidEncoding) do
|
||||||
|
@ -119,9 +119,9 @@ class CGICoreTest < Test::Unit::TestCase
|
||||||
$stdin.rewind
|
$stdin.rewind
|
||||||
cgi = CGI.new(:accept_charset=>"EUC-JP")
|
cgi = CGI.new(:accept_charset=>"EUC-JP")
|
||||||
## cgi[]
|
## 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
|
## 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
|
else
|
||||||
assert(true)
|
assert(true)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# frozen_string_literal: false
|
# frozen_string_literal: true
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
require 'cgi'
|
require 'cgi'
|
||||||
require 'time'
|
require 'time'
|
||||||
|
@ -58,7 +58,7 @@ class CGIHeaderTest < Test::Unit::TestCase
|
||||||
'expires' => Time.gm(2000, 1, 23, 12, 34, 56),
|
'expires' => Time.gm(2000, 1, 23, 12, 34, 56),
|
||||||
'location' => 'http://www.ruby-lang.org/',
|
'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 << "Server: webrick\r\n"
|
||||||
expected << "Connection: close\r\n"
|
expected << "Connection: close\r\n"
|
||||||
expected << "Content-Type: text/xhtml; charset=utf8\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::Cookie.new('name'=>'name2', 'value'=>'value2', 'secure'=>true),
|
||||||
]
|
]
|
||||||
cgi.instance_variable_set('@output_cookies', cookies)
|
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: name1=abc&123; path=\r\n"
|
||||||
expected << "Set-Cookie: name2=value2; path=; secure\r\n"
|
expected << "Set-Cookie: name2=value2; path=; secure\r\n"
|
||||||
expected << "\r\n"
|
expected << "\r\n"
|
||||||
|
@ -151,7 +151,7 @@ class CGIHeaderTest < Test::Unit::TestCase
|
||||||
actual.sub!(date, "Date: DATE_IS_REMOVED\r\n")
|
actual.sub!(date, "Date: DATE_IS_REMOVED\r\n")
|
||||||
end
|
end
|
||||||
## assertion
|
## 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 << "Date: DATE_IS_REMOVED\r\n"
|
||||||
expected << "Server: Apache 2.2.0\r\n"
|
expected << "Server: Apache 2.2.0\r\n"
|
||||||
expected << "Connection: close\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!(/^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")
|
expected.sub!(/\r\n\r\n/, "\r\nlocation: http://www.example.com/\r\n\r\n")
|
||||||
assert_equal(expected, actual3)
|
assert_equal(expected, actual3)
|
||||||
expected = "Content-Type: text/html\r\n"
|
expected = "Content-Type: text/html\r\n".dup
|
||||||
expected << "\r\n"
|
expected << "\r\n"
|
||||||
assert_equal(expected, actual4)
|
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 << "Content-Type: text/html\r\n"
|
||||||
expected << "location: http://www.example.com/\r\n"
|
expected << "location: http://www.example.com/\r\n"
|
||||||
expected << "\r\n"
|
expected << "\r\n"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# frozen_string_literal: false
|
# frozen_string_literal: true
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
require 'cgi'
|
require 'cgi'
|
||||||
require_relative 'update_env'
|
require_relative 'update_env'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# frozen_string_literal: false
|
# frozen_string_literal: true
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
require 'cgi'
|
require 'cgi'
|
||||||
require 'tempfile'
|
require 'tempfile'
|
||||||
|
@ -33,7 +33,7 @@ class MultiPart
|
||||||
|
|
||||||
def initialize(boundary=nil)
|
def initialize(boundary=nil)
|
||||||
@boundary = boundary || create_boundary()
|
@boundary = boundary || create_boundary()
|
||||||
@buf = ''
|
@buf = ''.dup
|
||||||
@buf.force_encoding(::Encoding::ASCII_8BIT) if defined?(::Encoding)
|
@buf.force_encoding(::Encoding::ASCII_8BIT) if defined?(::Encoding)
|
||||||
end
|
end
|
||||||
attr_reader :boundary
|
attr_reader :boundary
|
||||||
|
@ -53,7 +53,7 @@ class MultiPart
|
||||||
|
|
||||||
def close
|
def close
|
||||||
buf = @buf
|
buf = @buf
|
||||||
@buf = ''
|
@buf = ''.dup
|
||||||
return buf << "--#{boundary}--\r\n"
|
return buf << "--#{boundary}--\r\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -202,7 +202,7 @@ class CGIMultipartTest < Test::Unit::TestCase
|
||||||
@boundary = '----WebKitFormBoundaryAAfvAII+YL9102cX'
|
@boundary = '----WebKitFormBoundaryAAfvAII+YL9102cX'
|
||||||
@data = [
|
@data = [
|
||||||
{:name=>'hidden1', :value=>'foobar'},
|
{: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'),
|
{:name=>'file1', :value=>_read('file1.html'),
|
||||||
:filename=>'file1.html', :content_type=>'text/html'},
|
:filename=>'file1.html', :content_type=>'text/html'},
|
||||||
{:name=>'image1', :value=>_read('small.png'),
|
{:name=>'image1', :value=>_read('small.png'),
|
||||||
|
@ -218,7 +218,7 @@ class CGIMultipartTest < Test::Unit::TestCase
|
||||||
@boundary = '----WebKitFormBoundaryAAfvAII+YL9102cX'
|
@boundary = '----WebKitFormBoundaryAAfvAII+YL9102cX'
|
||||||
@data = [
|
@data = [
|
||||||
{:name=>'hidden1', :value=>'foobar'},
|
{: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'),
|
{:name=>'file1', :value=>_read('file1.html'),
|
||||||
:filename=>'file1.html', :content_type=>'text/html'},
|
:filename=>'file1.html', :content_type=>'text/html'},
|
||||||
{:name=>'image1', :value=>_read('large.png'),
|
{:name=>'image1', :value=>_read('large.png'),
|
||||||
|
@ -323,7 +323,7 @@ class CGIMultipartTest < Test::Unit::TestCase
|
||||||
@boundary = '(.|\n)*'
|
@boundary = '(.|\n)*'
|
||||||
@data = [
|
@data = [
|
||||||
{:name=>'hidden1', :value=>'foobar'},
|
{: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'),
|
{:name=>'file1', :value=>_read('file1.html'),
|
||||||
:filename=>'file1.html', :content_type=>'text/html'},
|
:filename=>'file1.html', :content_type=>'text/html'},
|
||||||
{:name=>'image1', :value=>_read('small.png'),
|
{:name=>'image1', :value=>_read('small.png'),
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# frozen_string_literal: false
|
# frozen_string_literal: true
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
require 'cgi'
|
require 'cgi'
|
||||||
require 'cgi/session'
|
require 'cgi/session'
|
||||||
|
@ -30,7 +30,7 @@ class CGISessionTest < Test::Unit::TestCase
|
||||||
'SERVER_PROTOCOL' => 'HTTP/1.1',
|
'SERVER_PROTOCOL' => 'HTTP/1.1',
|
||||||
)
|
)
|
||||||
value1="value1"
|
value1="value1"
|
||||||
value2="\x8F\xBC\x8D]"
|
value2="\x8F\xBC\x8D]".dup
|
||||||
value2.force_encoding("SJIS") if defined?(::Encoding)
|
value2.force_encoding("SJIS") if defined?(::Encoding)
|
||||||
cgi = CGI.new
|
cgi = CGI.new
|
||||||
session = CGI::Session.new(cgi,"tmpdir"=>@session_dir)
|
session = CGI::Session.new(cgi,"tmpdir"=>@session_dir)
|
||||||
|
@ -66,7 +66,7 @@ class CGISessionTest < Test::Unit::TestCase
|
||||||
'SERVER_PROTOCOL' => 'HTTP/1.1',
|
'SERVER_PROTOCOL' => 'HTTP/1.1',
|
||||||
)
|
)
|
||||||
value1="value1"
|
value1="value1"
|
||||||
value2="\x8F\xBC\x8D]"
|
value2="\x8F\xBC\x8D]".dup
|
||||||
value2.force_encoding("SJIS") if defined?(::Encoding)
|
value2.force_encoding("SJIS") if defined?(::Encoding)
|
||||||
cgi = CGI.new
|
cgi = CGI.new
|
||||||
session = CGI::Session.new(cgi,"tmpdir"=>@session_dir,"database_manager"=>CGI::Session::PStore)
|
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',
|
'SERVER_PROTOCOL' => 'HTTP/1.1',
|
||||||
)
|
)
|
||||||
value1="value1"
|
value1="value1"
|
||||||
value2="\x8F\xBC\x8D]"
|
value2="\x8F\xBC\x8D]".dup
|
||||||
value2.force_encoding("SJIS") if defined?(::Encoding)
|
value2.force_encoding("SJIS") if defined?(::Encoding)
|
||||||
cgi = CGI.new
|
cgi = CGI.new
|
||||||
session = CGI::Session.new(cgi,"tmpdir"=>@session_dir,"session_id"=>"foo")
|
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',
|
'SERVER_PROTOCOL' => 'HTTP/1.1',
|
||||||
)
|
)
|
||||||
value1="value1"
|
value1="value1"
|
||||||
value2="\x8F\xBC\x8D]"
|
value2="\x8F\xBC\x8D]".dup
|
||||||
value2.force_encoding("SJIS") if defined?(::Encoding)
|
value2.force_encoding("SJIS") if defined?(::Encoding)
|
||||||
cgi = CGI.new
|
cgi = CGI.new
|
||||||
session = CGI::Session.new(cgi,"tmpdir"=>@session_dir,"session_key"=>"bar")
|
session = CGI::Session.new(cgi,"tmpdir"=>@session_dir,"session_key"=>"bar")
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# frozen_string_literal: false
|
# frozen_string_literal: true
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
require 'cgi'
|
require 'cgi'
|
||||||
require 'stringio'
|
require 'stringio'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# frozen_string_literal: false
|
# frozen_string_literal: true
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
require 'cgi'
|
require 'cgi'
|
||||||
require 'stringio'
|
require 'stringio'
|
||||||
|
@ -15,7 +15,7 @@ class CGIUtilTest < Test::Unit::TestCase
|
||||||
'REQUEST_METHOD' => 'GET',
|
'REQUEST_METHOD' => 'GET',
|
||||||
'SCRIPT_NAME' => nil,
|
'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)
|
@str1.force_encoding("UTF-8") if defined?(::Encoding)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -31,14 +31,14 @@ class CGIUtilTest < Test::Unit::TestCase
|
||||||
|
|
||||||
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\<\<".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\<\<".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\<\<".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\<\<".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
|
||||||
|
@ -51,9 +51,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".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".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".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
|
||||||
|
@ -72,7 +72,7 @@ class CGIUtilTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_cgi_escape_html_duplicated
|
def test_cgi_escape_html_duplicated
|
||||||
orig = "Ruby".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)
|
||||||
|
@ -90,10 +90,10 @@ 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("'&\"><".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".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
|
||||||
|
|
Loading…
Reference in a new issue