Skip to content

Commit bacbde8

Browse files
committed
Update stdlib from ruby 2.1 HEAD.
1 parent 3750915 commit bacbde8

File tree

15 files changed

+76
-36
lines changed

15 files changed

+76
-36
lines changed

lib/ruby/2.1/csv.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,9 +1148,9 @@ def self.generate(*args)
11481148
io.seek(0, IO::SEEK_END)
11491149
args.unshift(io)
11501150
else
1151-
encoding = (args[-1] = args[-1].dup).delete(:encoding) if args.last.is_a?(Hash)
1151+
encoding = args[-1][:encoding] if args.last.is_a?(Hash)
11521152
str = ""
1153-
str.encode!(encoding) if encoding
1153+
str.force_encoding(encoding) if encoding
11541154
args.unshift(str)
11551155
end
11561156
csv = new(*args) # wrap
@@ -1515,7 +1515,7 @@ def initialize(data, options = Hash.new)
15151515
init_headers(options)
15161516
init_comments(options)
15171517

1518-
options.delete(:encoding)
1518+
@force_encoding = !!(encoding || options.delete(:encoding))
15191519
options.delete(:internal_encoding)
15201520
options.delete(:external_encoding)
15211521
unless options.empty?
@@ -1655,10 +1655,13 @@ def <<(row)
16551655

16561656
output = row.map(&@quote).join(@col_sep) + @row_sep # quote and separate
16571657
if @io.is_a?(StringIO) and
1658-
output.encoding != raw_encoding and
1659-
(compatible_encoding = Encoding.compatible?(@io.string, output))
1660-
@io.set_encoding(compatible_encoding)
1661-
@io.seek(0, IO::SEEK_END)
1658+
output.encoding != (encoding = raw_encoding)
1659+
if @force_encoding
1660+
output = output.encode(encoding)
1661+
elsif (compatible_encoding = Encoding.compatible?(@io.string, output))
1662+
@io.set_encoding(compatible_encoding)
1663+
@io.seek(0, IO::SEEK_END)
1664+
end
16621665
end
16631666
@io << output
16641667

lib/ruby/2.1/erb.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ def run(b=new_toplevel)
837837
# the results of that code. (See ERB::new for details on how this process
838838
# can be affected by _safe_level_.)
839839
#
840-
# _b_ accepts a Binding or Proc object which is used to set the context of
840+
# _b_ accepts a Binding object which is used to set the context of
841841
# code evaluation.
842842
#
843843
def result(b=new_toplevel)

lib/ruby/2.1/fileutils.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def rmdir(list, options = {})
277277
Dir.rmdir(dir)
278278
end
279279
end
280-
rescue Errno::ENOTEMPTY, Errno::ENOENT
280+
rescue Errno::ENOTEMPTY, Errno::EEXIST, Errno::ENOENT
281281
end
282282
end
283283
end
@@ -864,7 +864,8 @@ def install(src, dest, options = {})
864864
fu_check_options options, OPT_TABLE['install']
865865
fu_output_message "install -c#{options[:preserve] && ' -p'}#{options[:mode] ? (' -m 0%o' % options[:mode]) : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
866866
return if options[:noop]
867-
fu_each_src_dest(src, dest) do |s, d, st|
867+
fu_each_src_dest(src, dest) do |s, d|
868+
st = File.stat(s)
868869
unless File.exist?(d) and compare_file(s, d)
869870
remove_file d, true
870871
copy_file s, d
@@ -1262,7 +1263,12 @@ def dereference?
12621263
end
12631264

12641265
def exist?
1265-
lstat! ? true : false
1266+
begin
1267+
lstat
1268+
true
1269+
rescue Errno::ENOENT
1270+
false
1271+
end
12661272
end
12671273

12681274
def file?
@@ -1580,7 +1586,7 @@ def fu_list(arg) #:nodoc:
15801586
def fu_each_src_dest(src, dest) #:nodoc:
15811587
fu_each_src_dest0(src, dest) do |s, d|
15821588
raise ArgumentError, "same file: #{s} and #{d}" if fu_same?(s, d)
1583-
yield s, d, File.stat(s)
1589+
yield s, d
15841590
end
15851591
end
15861592
private_module_function :fu_each_src_dest

lib/ruby/2.1/find.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def find(*paths) # :yield: path
4040
fs_encoding = Encoding.find("filesystem")
4141

4242
paths.collect!{|d| raise Errno::ENOENT unless File.exist?(d); d.dup}.each do |path|
43+
path = path.to_path if path.respond_to? :to_path
4344
enc = path.encoding == Encoding::US_ASCII ? fs_encoding : path.encoding
4445
ps = [path]
4546
while file = ps.shift

lib/ruby/2.1/gserver.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
# super(port, *args)
3838
# end
3939
# def serve(io)
40-
# io.puts(Time.now.to_s)
40+
# io.puts(Time.now.to_i)
4141
# end
4242
# end
4343
#
@@ -144,7 +144,7 @@ def join
144144
attr_reader :port
145145
# Host on which to bind, as a String
146146
attr_reader :host
147-
# Maximum number of connections to accept at at ime, as a Fixnum
147+
# Maximum number of connections to accept at a time, as a Fixnum
148148
attr_reader :maxConnections
149149
# IO Device on which log messages should be written
150150
attr_accessor :stdlog
@@ -156,7 +156,7 @@ def join
156156

157157
# Called when a client connects, if auditing is enabled.
158158
#
159-
# +client+:: a TCPSocket instances representing the client that connected
159+
# +client+:: a TCPSocket instance representing the client that connected
160160
#
161161
# Return true to allow this client to connect, false to prevent it.
162162
def connecting(client)
@@ -192,7 +192,7 @@ def stopping()
192192
# Called if #debug is true whenever an unhandled exception is raised.
193193
# This implementation simply logs the backtrace.
194194
#
195-
# +detail+:: The Exception that was caught
195+
# +detail+:: the Exception that was caught
196196
def error(detail)
197197
log(detail.backtrace.join("\n"))
198198
end
@@ -212,9 +212,9 @@ def log(msg)
212212

213213
# Create a new server
214214
#
215-
# +port+:: the port, as a Fixnum, on which to listen.
215+
# +port+:: the port, as a Fixnum, on which to listen
216216
# +host+:: the host to bind to
217-
# +maxConnections+:: The maximum number of simultaneous connections to
217+
# +maxConnections+:: the maximum number of simultaneous connections to
218218
# accept
219219
# +stdlog+:: IO device on which to log messages
220220
# +audit+:: if true, lifecycle callbacks will be called. See #audit

lib/ruby/2.1/matrix.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,9 +1764,9 @@ def inner_product(v)
17641764
#
17651765
def cross_product(v)
17661766
Vector.Raise ErrDimensionMismatch unless size == v.size && v.size == 3
1767-
Vector[ v[1]*@elements[2] - v[2]*@elements[1],
1768-
v[2]*@elements[0] - v[0]*@elements[2],
1769-
v[0]*@elements[1] - v[1]*@elements[0] ]
1767+
Vector[ v[2]*@elements[1] - v[1]*@elements[2],
1768+
v[0]*@elements[2] - v[2]*@elements[0],
1769+
v[1]*@elements[0] - v[0]*@elements[1] ]
17701770
end
17711771

17721772
#

lib/ruby/2.1/net/ftp.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,13 +1105,16 @@ def read(len = nil)
11051105
end
11061106

11071107
def gets
1108-
return readuntil("\n")
1109-
rescue EOFError
1110-
return nil
1108+
line = readuntil("\n", true)
1109+
return line.empty? ? nil : line
11111110
end
11121111

11131112
def readline
1114-
return readuntil("\n")
1113+
line = gets
1114+
if line.nil?
1115+
raise EOFError, "end of file reached"
1116+
end
1117+
return line
11151118
end
11161119
end
11171120
# :startdoc:

lib/ruby/2.1/net/imap.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2372,6 +2372,8 @@ def body_type_1part
23722372
return body_type_msg
23732373
when /\A(?:ATTACHMENT)\z/ni
23742374
return body_type_attachment
2375+
when /\A(?:MIXED)\z/ni
2376+
return body_type_mixed
23752377
else
23762378
return body_type_basic
23772379
end
@@ -2454,6 +2456,13 @@ def body_type_attachment
24542456
return BodyTypeAttachment.new(mtype, nil, param)
24552457
end
24562458

2459+
def body_type_mixed
2460+
mtype = "MULTIPART"
2461+
msubtype = case_insensitive_string
2462+
param, disposition, language, extension = body_ext_mpart
2463+
return BodyTypeBasic.new(mtype, msubtype, param, nil, nil, nil, nil, nil, disposition, language, extension)
2464+
end
2465+
24572466
def body_type_mpart
24582467
parts = []
24592468
while true

lib/ruby/2.1/pathname.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class Pathname
2222
end
2323

2424
SAME_PATHS = if File::FNM_SYSCASE.nonzero?
25-
proc {|a, b| a.casecmp(b).zero?}
25+
# Avoid #zero? here because #casecmp can return nil.
26+
proc {|a, b| a.casecmp(b) == 0}
2627
else
2728
proc {|a, b| a == b}
2829
end
@@ -113,6 +114,7 @@ def cleanpath_aggressive # :nodoc:
113114
end
114115
end
115116
end
117+
pre.tr!(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
116118
if /#{SEPARATOR_PAT}/o =~ File.basename(pre)
117119
names.shift while names[0] == '..'
118120
end
@@ -161,6 +163,7 @@ def cleanpath_conservative # :nodoc:
161163
pre, base = r
162164
names.unshift base if base != '.'
163165
end
166+
pre.tr!(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
164167
if /#{SEPARATOR_PAT}/o =~ File.basename(pre)
165168
names.shift while names[0] == '..'
166169
end

lib/ruby/2.1/resolv.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,9 @@ def self.bind_random_port(udpsock, bind_host="0.0.0.0") # :nodoc:
657657
begin
658658
port = rangerand(1024..65535)
659659
udpsock.bind(bind_host, port)
660-
rescue Errno::EADDRINUSE, Errno::EACCES
660+
rescue Errno::EADDRINUSE, # POSIX
661+
Errno::EACCES, # SunOS: See PRIV_SYS_NFS in privileges(5)
662+
Errno::EPERM # FreeBSD: security.mac.portacl.port_high is configurable. See mac_portacl(4).
661663
retry
662664
end
663665
end

lib/ruby/2.1/rexml/entity.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,14 @@ def value
138138
matches = @value.scan(PEREFERENCE_RE)
139139
rv = @value.clone
140140
if @parent
141+
sum = 0
141142
matches.each do |entity_reference|
142143
entity_value = @parent.entity( entity_reference[0] )
144+
if sum + entity_value.bytesize > Security.entity_expansion_text_limit
145+
raise "entity expansion has grown too large"
146+
else
147+
sum += entity_value.bytesize
148+
end
143149
rv.gsub!( /%#{entity_reference.join};/um, entity_value )
144150
end
145151
end

lib/ruby/2.1/rinda/tuplespace.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def expired?
7676
# Reset the expiry time according to +sec_or_renewer+.
7777
#
7878
# +nil+:: it is set to expire in the far future.
79-
# +false+:: it has expired.
79+
# +true+:: it has expired.
8080
# Numeric:: it will expire in that many seconds.
8181
#
8282
# Otherwise the argument refers to some kind of renewer object

lib/ruby/2.1/test/unit/parallel.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ def _report(res, *args) # :nodoc:
155155
end
156156

157157
def puke(klass, meth, e) # :nodoc:
158+
if e.is_a?(MiniTest::Skip)
159+
new_e = MiniTest::Skip.new(e.message)
160+
new_e.set_backtrace(e.backtrace)
161+
e = new_e
162+
end
158163
@partial_report << [klass.name, meth, e.is_a?(MiniTest::Assertion) ? e : ProxyError.new(e)]
159164
super
160165
end

lib/ruby/2.1/time.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,13 @@ def make_time(year, mon, day, hour, min, sec, sec_fraction, zone, now)
278278
# supplied with those of +now+. For the lower components, the minimum
279279
# values (1 or 0) are assumed if broken or missing. For example:
280280
#
281-
# # Suppose it is "Thu Nov 29 14:33:20 GMT 2001" now and
282-
# # your time zone is GMT:
283-
# now = Time.parse("Thu Nov 29 14:33:20 GMT 2001")
284-
# Time.parse("16:30", now) #=> 2001-11-29 16:30:00 +0900
285-
# Time.parse("7/23", now) #=> 2001-07-23 00:00:00 +0900
286-
# Time.parse("Aug 31", now) #=> 2001-08-31 00:00:00 +0900
287-
# Time.parse("Aug 2000", now) #=> 2000-08-01 00:00:00 +0900
281+
# # Suppose it is "Thu Nov 29 14:33:20 2001" now and
282+
# # your time zone is EST which is GMT-5.
283+
# now = Time.parse("Thu Nov 29 14:33:20 2001")
284+
# Time.parse("16:30", now) #=> 2001-11-29 16:30:00 -0500
285+
# Time.parse("7/23", now) #=> 2001-07-23 00:00:00 -0500
286+
# Time.parse("Aug 31", now) #=> 2001-08-31 00:00:00 -0500
287+
# Time.parse("Aug 2000", now) #=> 2000-08-01 00:00:00 -0500
288288
#
289289
# Since there are numerous conflicts among locally defined time zone
290290
# abbreviations all over the world, this method is not intended to

lib/ruby/2.1/webrick/utils.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ def create_listeners(address, port, logger=nil)
7575
sockets = Socket.tcp_server_sockets(address, port)
7676
sockets = sockets.map {|s|
7777
s.autoclose = false
78-
TCPServer.for_fd(s.fileno)
78+
ts = TCPServer.for_fd(s.fileno)
79+
s.close
80+
ts
7981
}
8082
return sockets
8183
end

0 commit comments

Comments
 (0)