Skip to content

Commit 5a70e9c

Browse files
nobuhsbt
authored andcommitted
Constified unusable chars
1 parent b687363 commit 5a70e9c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/tmpdir.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ def tmpdir
112112
Dir.tmpdir
113113
end
114114

115+
UNUSABLE_CHARS = [File::SEPARATOR, File::ALT_SEPARATOR, File::PATH_SEPARATOR, ":"].uniq.join("").freeze
116+
115117
def create(basename, tmpdir=nil, max_try: nil, **opts)
116118
if $SAFE > 0 and tmpdir.tainted?
117119
tmpdir = '/tmp'
@@ -123,10 +125,10 @@ def create(basename, tmpdir=nil, max_try: nil, **opts)
123125
prefix, suffix = basename
124126
prefix = (String.try_convert(prefix) or
125127
raise ArgumentError, "unexpected prefix: #{prefix.inspect}")
126-
prefix = prefix.delete("#{File::SEPARATOR}#{File::ALT_SEPARATOR}")
128+
prefix = prefix.delete(UNUSABLE_CHARS)
127129
suffix &&= (String.try_convert(suffix) or
128130
raise ArgumentError, "unexpected suffix: #{suffix.inspect}")
129-
suffix &&= suffix.delete("#{File::SEPARATOR}#{File::ALT_SEPARATOR}")
131+
suffix &&= suffix.delete(UNUSABLE_CHARS)
130132
begin
131133
t = Time.now.strftime("%Y%m%d")
132134
path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"\

0 commit comments

Comments
 (0)