ruby-changes:56185
From: Nobuyoshi <ko1@a...>
Date: Fri, 21 Jun 2019 23:04:59 +0900 (JST)
Subject: [ruby-changes:56185] Nobuyoshi Nakada: 1c7e303b26 (trunk): Constified unusable chars
https://git.ruby-lang.org/ruby.git/commit/?id=1c7e303b26 From 1c7e303b26090205f393595f15dadddd4b2d31b6 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Fri, 21 Jun 2019 23:03:36 +0900 Subject: Constified unusable chars diff --git a/lib/tmpdir.rb b/lib/tmpdir.rb index 87e53a8..05e74eb 100644 --- a/lib/tmpdir.rb +++ b/lib/tmpdir.rb @@ -112,6 +112,8 @@ class Dir https://github.com/ruby/ruby/blob/trunk/lib/tmpdir.rb#L112 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 https://github.com/ruby/ruby/blob/trunk/lib/tmpdir.rb#L125 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)}"\ -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/