Skip to content

Commit

Permalink
Constified unusable chars
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Jun 21, 2019
1 parent 551ef27 commit 1c7e303
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/tmpdir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ def tmpdir
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'
Expand All @@ -123,10 +125,10 @@ def create(basename, tmpdir=nil, max_try: nil, **opts)
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)}"\
Expand Down

0 comments on commit 1c7e303

Please sign in to comment.