Skip to content

Commit

Permalink
Showing 35 changed files with 1,024 additions and 331 deletions.
14 changes: 7 additions & 7 deletions lib/ruby/stdlib/bigdecimal/math.rb
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@
# include BigMath
#
# a = BigDecimal((PI(100)/2).to_s)
# puts sin(a,100) # => 0.10000000000000000000......E1
# puts sin(a,100) # => 0.99999999999999999999......e0
#
module BigMath
module_function
@@ -39,7 +39,7 @@ module BigMath
# precision, +numeric+.
#
# BigMath.sqrt(BigDecimal.new('2'), 16).to_s
# #=> "0.1414213562373095048801688724E1"
# #=> "0.1414213562373095048801688724e1"
#
def sqrt(x, prec)
x.sqrt(prec)
@@ -54,7 +54,7 @@ def sqrt(x, prec)
# If +decimal+ is Infinity or NaN, returns NaN.
#
# BigMath.sin(BigMath.PI(5)/4, 5).to_s
# #=> "0.70710678118654752440082036563292800375E0"
# #=> "0.70710678118654752440082036563292800375e0"
#
def sin(x, prec)
raise ArgumentError, "Zero or negative precision for sin" if prec <= 0
@@ -98,7 +98,7 @@ def sin(x, prec)
# If +decimal+ is Infinity or NaN, returns NaN.
#
# BigMath.cos(BigMath.PI(4), 16).to_s
# #=> "-0.999999999999999999999999999999856613163740061349E0"
# #=> "-0.999999999999999999999999999999856613163740061349e0"
#
def cos(x, prec)
raise ArgumentError, "Zero or negative precision for cos" if prec <= 0
@@ -142,7 +142,7 @@ def cos(x, prec)
# If +decimal+ is NaN, returns NaN.
#
# BigMath.atan(BigDecimal.new('-1'), 16).to_s
# #=> "-0.785398163397448309615660845819878471907514682065E0"
# #=> "-0.785398163397448309615660845819878471907514682065e0"
#
def atan(x, prec)
raise ArgumentError, "Zero or negative precision for atan" if prec <= 0
@@ -179,7 +179,7 @@ def atan(x, prec)
# +numeric+.
#
# BigMath.PI(10).to_s
# #=> "0.3141592653589793238462643388813853786957412E1"
# #=> "0.3141592653589793238462643388813853786957412e1"
#
def PI(prec)
raise ArgumentError, "Zero or negative precision for PI" if prec <= 0
@@ -224,7 +224,7 @@ def PI(prec)
# digits of precision, +numeric+.
#
# BigMath.E(10).to_s
# #=> "0.271828182845904523536028752390026306410273E1"
# #=> "0.271828182845904523536028752390026306410273e1"
#
def E(prec)
raise ArgumentError, "Zero or negative precision for E" if prec <= 0
10 changes: 5 additions & 5 deletions lib/ruby/stdlib/bigdecimal/util.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: false
# BigDecimal extends the native Integer class to provide the #to_d method.
#
# When you require the BigDecimal library in your application, this methodwill
# When you require the BigDecimal library in your application, this method will
# be available on Integer objects.
class Integer < Numeric
# call-seq:
@@ -13,7 +13,7 @@ class Integer < Numeric
# require 'bigdecimal/util'
#
# 42.to_d
# # => #<BigDecimal:1008ef070,'0.42E2',9(36)>
# # => 0.42e2
#
def to_d
BigDecimal(self)
@@ -34,7 +34,7 @@ class Float < Numeric
# require 'bigdecimal/util'
#
# 0.5.to_d
# # => #<BigDecimal:1dc69e0,'0.5E0',9(18)>
# # => 0.5e0
#
def to_d(precision=nil)
BigDecimal(self, precision || Float::DIG)
@@ -55,7 +55,7 @@ class String
# require 'bigdecimal/util'
#
# "0.5".to_d
# # => #<BigDecimal:1dc69e0,'0.5E0',9(18)>
# # => 0.5e0
#
def to_d
BigDecimal(self)
@@ -117,7 +117,7 @@ class Rational < Numeric
# r = (22/7.0).to_r
# # => (7077085128725065/2251799813685248)
# r.to_d(3)
# # => #<BigDecimal:1a44d08,'0.314E1',18(36)>
# # => 0.314e1
def to_d(precision)
if precision <= 0
raise ArgumentError, "negative precision"
2 changes: 1 addition & 1 deletion lib/ruby/stdlib/cgi/session.rb
Original file line number Diff line number Diff line change
@@ -426,7 +426,7 @@ def update
f.close
File.rename @path+".new", @path
ensure
f.close if f and !f.closed?
f.close if f
lockf.close if lockf
end
end
2 changes: 1 addition & 1 deletion lib/ruby/stdlib/csv.rb
Original file line number Diff line number Diff line change
@@ -1927,7 +1927,7 @@ def shift
if @io.eof?
raise MalformedCSVError,
"Unclosed quoted field on line #{lineno + 1}."
elsif @field_size_limit and csv.last.size >= @field_size_limit
elsif @field_size_limit and csv.last.sum(&:size) >= @field_size_limit
raise MalformedCSVError, "Field size exceeded on line #{lineno + 1}."
end
# otherwise, we need to loop and pull some more data to complete the row
108 changes: 57 additions & 51 deletions lib/ruby/stdlib/fileutils.rb
Original file line number Diff line number Diff line change
@@ -16,19 +16,19 @@
# require 'fileutils'
#
# FileUtils.cd(dir, options)
# FileUtils.cd(dir, options) {|dir| .... }
# FileUtils.cd(dir, options) {|dir| block }
# FileUtils.pwd()
# FileUtils.mkdir(dir, options)
# FileUtils.mkdir(list, options)
# FileUtils.mkdir_p(dir, options)
# FileUtils.mkdir_p(list, options)
# FileUtils.rmdir(dir, options)
# FileUtils.rmdir(list, options)
# FileUtils.ln(old, new, options)
# FileUtils.ln(list, destdir, options)
# FileUtils.ln_s(old, new, options)
# FileUtils.ln_s(list, destdir, options)
# FileUtils.ln_sf(src, dest, options)
# FileUtils.ln(target, link, options)
# FileUtils.ln(targets, dir, options)
# FileUtils.ln_s(target, link, options)
# FileUtils.ln_s(targets, dir, options)
# FileUtils.ln_sf(target, link, options)
# FileUtils.cp(src, dest, options)
# FileUtils.cp(list, dir, options)
# FileUtils.cp_r(src, dest, options)
@@ -38,7 +38,7 @@
# FileUtils.rm(list, options)
# FileUtils.rm_r(list, options)
# FileUtils.rm_rf(list, options)
# FileUtils.install(src, dest, mode = <src's>, options)
# FileUtils.install(src, dest, options)
# FileUtils.chmod(mode, list, options)
# FileUtils.chmod_R(mode, list, options)
# FileUtils.chown(user, group, list, options)
@@ -47,7 +47,7 @@
#
# The <tt>options</tt> parameter is a hash of options, taken from the list
# <tt>:force</tt>, <tt>:noop</tt>, <tt>:preserve</tt>, and <tt>:verbose</tt>.
# <tt>:noop</tt> means that no changes are made. The other two are obvious.
# <tt>:noop</tt> means that no changes are made. The other three are obvious.
# Each method documents the options that it honours.
#
# All methods that have the concept of a "source" file or directory can take
@@ -112,7 +112,7 @@ def pwd
# FileUtils.cd('/', :verbose => true) # chdir and report it
#
# FileUtils.cd('/') do # chdir
# [...] # do something
# # ... # do something
# end # return to original directory
#
def cd(dir, verbose: nil, &block) # :yield: dir
@@ -144,7 +144,7 @@ def uptodate?(new, old_list)
end
module_function :uptodate?

def remove_trailing_slash(dir)
def remove_trailing_slash(dir) #:nodoc:
dir == '/' ? dir : dir.chomp(?/)
end
private_module_function :remove_trailing_slash
@@ -175,10 +175,11 @@ def mkdir(list, mode: nil, noop: nil, verbose: nil)
# FileUtils.mkdir_p '/usr/local/lib/ruby'
#
# causes to make following directories, if it does not exist.
# * /usr
# * /usr/local
# * /usr/local/lib
# * /usr/local/lib/ruby
#
# * /usr
# * /usr/local
# * /usr/local/lib
# * /usr/local/lib/ruby
#
# You can pass several directories at a time in a list.
#
@@ -258,23 +259,24 @@ def rmdir(list, parents: nil, noop: nil, verbose: nil)
module_function :rmdir

#
# <b><tt>ln(old, new, **options)</tt></b>
# :call-seq:
# FileUtils.ln(target, link, force: nil, noop: nil, verbose: nil)
# FileUtils.ln(target, dir, force: nil, noop: nil, verbose: nil)
# FileUtils.ln(targets, dir, force: nil, noop: nil, verbose: nil)
#
# Creates a hard link +new+ which points to +old+.
# If +new+ already exists and it is a directory, creates a link +new/old+.
# If +new+ already exists and it is not a directory, raises Errno::EEXIST.
# But if :force option is set, overwrite +new+.
# In the first form, creates a hard link +link+ which points to +target+.
# If +link+ already exists, raises Errno::EEXIST.
# But if the :force option is set, overwrites +link+.
#
# FileUtils.ln 'gcc', 'cc', :verbose => true
# FileUtils.ln 'gcc', 'cc', verbose: true
# FileUtils.ln '/usr/bin/emacs21', '/usr/bin/emacs'
#
# <b><tt>ln(list, destdir, **options)</tt></b>
#
# Creates several hard links in a directory, with each one pointing to the
# item in +list+. If +destdir+ is not a directory, raises Errno::ENOTDIR.
# In the second form, creates a link +dir/target+ pointing to +target+.
# In the third form, creates several hard links in the directory +dir+,
# pointing to each item in +targets+.
# If +dir+ is not a directory, raises Errno::ENOTDIR.
#
# include FileUtils
# cd '/sbin'
# FileUtils.cd '/sbin'
# FileUtils.ln %w(cp mv mkdir), '/bin' # Now /sbin/cp and /bin/cp are linked.
#
def ln(src, dest, force: nil, noop: nil, verbose: nil)
@@ -291,24 +293,24 @@ def ln(src, dest, force: nil, noop: nil, verbose: nil)
module_function :link

#
# <b><tt>ln_s(old, new, **options)</tt></b>
# :call-seq:
# FileUtils.ln_s(target, link, force: nil, noop: nil, verbose: nil)
# FileUtils.ln_s(target, dir, force: nil, noop: nil, verbose: nil)
# FileUtils.ln_s(targets, dir, force: nil, noop: nil, verbose: nil)
#
# Creates a symbolic link +new+ which points to +old+. If +new+ already
# exists and it is a directory, creates a symbolic link +new/old+. If +new+
# already exists and it is not a directory, raises Errno::EEXIST. But if
# :force option is set, overwrite +new+.
# In the first form, creates a symbolic link +link+ which points to +target+.
# If +link+ already exists, raises Errno::EEXIST.
# But if the :force option is set, overwrites +link+.
#
# FileUtils.ln_s '/usr/bin/ruby', '/usr/local/bin/ruby'
# FileUtils.ln_s 'verylongsourcefilename.c', 'c', :force => true
#
# <b><tt>ln_s(list, destdir, **options)</tt></b>
# FileUtils.ln_s 'verylongsourcefilename.c', 'c', force: true
#
# Creates several symbolic links in a directory, with each one pointing to the
# item in +list+. If +destdir+ is not a directory, raises Errno::ENOTDIR.
# In the second form, creates a link +dir/target+ pointing to +target+.
# In the third form, creates several symbolic links in the directory +dir+,
# pointing to each item in +targets+.
# If +dir+ is not a directory, raises Errno::ENOTDIR.
#
# If +destdir+ is not a directory, raises Errno::ENOTDIR.
#
# FileUtils.ln_s Dir.glob('bin/*.rb'), '/home/aamine/bin'
# FileUtils.ln_s Dir.glob('/bin/*.rb'), '/home/foo/bin'
#
def ln_s(src, dest, force: nil, noop: nil, verbose: nil)
fu_output_message "ln -s#{force ? 'f' : ''} #{[src,dest].flatten.join ' '}" if verbose
@@ -323,9 +325,13 @@ def ln_s(src, dest, force: nil, noop: nil, verbose: nil)
alias symlink ln_s
module_function :symlink

#
# :call-seq:
# FileUtils.ln_sf(*args)
#
# Same as
# #ln_s(src, dest, :force => true)
#
# FileUtils.ln_s(*args, force: true)
#
def ln_sf(src, dest, noop: nil, verbose: nil)
ln_s src, dest, force: true, noop: noop, verbose: verbose
@@ -368,7 +374,7 @@ def cp(src, dest, preserve: nil, noop: nil, verbose: nil)
#
# # Examples of copying several files to target directory.
# FileUtils.cp_r %w(mail.rb field.rb debug/), site_ruby + '/tmail'
# FileUtils.cp_r Dir.glob('*.rb'), '/home/aamine/lib/ruby', :noop => true, :verbose => true
# FileUtils.cp_r Dir.glob('*.rb'), '/home/foo/lib/ruby', :noop => true, :verbose => true
#
# # If you want to copy all contents of a directory instead of the
# # directory itself, c.f. src/x -> dest/x, src/y -> dest/y,
@@ -442,7 +448,7 @@ def copy_stream(src, dest)
# FileUtils.mv 'badname.rb', 'goodname.rb'
# FileUtils.mv 'stuff.rb', '/notexist/lib/ruby', :force => true # no error
#
# FileUtils.mv %w(junk.txt dust.txt), '/home/aamine/.trash/'
# FileUtils.mv %w(junk.txt dust.txt), '/home/foo/.trash/'
# FileUtils.mv Dir.glob('test*.rb'), 'test', :noop => true, :verbose => true
#
def mv(src, dest, force: nil, noop: nil, verbose: nil, secure: nil)
@@ -517,7 +523,7 @@ def rm(list, force: nil, noop: nil, verbose: nil)
#
# Equivalent to
#
# #rm(list, :force => true)
# FileUtils.rm(list, :force => true)
#
def rm_f(list, noop: nil, verbose: nil)
rm list, force: true, noop: noop, verbose: verbose
@@ -533,7 +539,7 @@ def rm_f(list, noop: nil, verbose: nil)
# StandardError when :force option is set.
#
# FileUtils.rm_r Dir.glob('/tmp/*')
# FileUtils.rm_r '/', :force => true # :-)
# FileUtils.rm_r 'some_dir', :force => true
#
# WARNING: This method causes local vulnerability
# if one of parent directories or removing directory tree are world
@@ -563,7 +569,7 @@ def rm_r(list, force: nil, noop: nil, verbose: nil, secure: nil)
#
# Equivalent to
#
# #rm_r(list, :force => true)
# FileUtils.rm_r(list, :force => true)
#
# WARNING: This method causes local vulnerability.
# Read the documentation of #rm_r first.
@@ -583,9 +589,9 @@ def rm_rf(list, noop: nil, verbose: nil, secure: nil)
# (time-of-check-to-time-of-use) local security vulnerability of #rm_r.
# #rm_r causes security hole when:
#
# * Parent directory is world writable (including /tmp).
# * Removing directory tree includes world writable directory.
# * The system has symbolic link.
# * Parent directory is world writable (including /tmp).
# * Removing directory tree includes world writable directory.
# * The system has symbolic link.
#
# To avoid this security hole, this method applies special preprocess.
# If +path+ is a directory, this method chown(2) and chmod(2) all
@@ -603,8 +609,8 @@ def rm_rf(list, noop: nil, verbose: nil, secure: nil)
#
# For details of this security vulnerability, see Perl's case:
#
# http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=CAN-2005-0448
# http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=CAN-2004-0452
# * http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=CAN-2005-0448
# * http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=CAN-2004-0452
#
# For fileutils.rb, this vulnerability is reported in [ruby-dev:26100].
#
@@ -809,7 +815,7 @@ def user_mask(target) #:nodoc:
end
private_module_function :user_mask

def apply_mask(mode, user_mask, op, mode_mask)
def apply_mask(mode, user_mask, op, mode_mask) #:nodoc:
case op
when '='
(mode & ~user_mask) | (user_mask & mode_mask)
Loading

0 comments on commit 777a5a3

Please sign in to comment.