mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Constified unusable chars
This commit is contained in:
parent
551ef27490
commit
1c7e303b26
1 changed files with 4 additions and 2 deletions
|
@ -112,6 +112,8 @@ class Dir
|
|||
Dir.tmpdir
|
||||
end
|
||||
|
||||
UNUSABLE_CHARS = [File::SEPARATOR, File::ALT_SEPARATOR, File::PATH_SEPARATOR, ":"].uniq.join("").freeze
|
||||
|
||||
def create(basename, tmpdir=nil, max_try: nil, **opts)
|
||||
if $SAFE > 0 and tmpdir.tainted?
|
||||
tmpdir = '/tmp'
|
||||
|
@ -123,10 +125,10 @@ class Dir
|
|||
prefix, suffix = basename
|
||||
prefix = (String.try_convert(prefix) or
|
||||
raise ArgumentError, "unexpected prefix: #{prefix.inspect}")
|
||||
prefix = prefix.delete("#{File::SEPARATOR}#{File::ALT_SEPARATOR}")
|
||||
prefix = prefix.delete(UNUSABLE_CHARS)
|
||||
suffix &&= (String.try_convert(suffix) or
|
||||
raise ArgumentError, "unexpected suffix: #{suffix.inspect}")
|
||||
suffix &&= suffix.delete("#{File::SEPARATOR}#{File::ALT_SEPARATOR}")
|
||||
suffix &&= suffix.delete(UNUSABLE_CHARS)
|
||||
begin
|
||||
t = Time.now.strftime("%Y%m%d")
|
||||
path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"\
|
||||
|
|
Loading…
Reference in a new issue