From ed68d975d068e27b6ebe13a3f1e1e010d9bdea49 Mon Sep 17 00:00:00 2001 From: "maruel@chromium.org" Date: Tue, 2 Nov 2010 19:15:15 +0000 Subject: [PATCH] Blacklist more characters when sending a try job. Otherwise files containing these characters can be created on the file system, making it harder to get rid of those files. TEST=none BUG=none Review URL: http://codereview.chromium.org/4127014 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@64782 0039d316-1c4b-4281-b951-d872f2087c98 --- tests/trychange_unittest.py | 2 +- trychange.py | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/trychange_unittest.py b/tests/trychange_unittest.py index 2ebfd9240..4ee984a85 100755 --- a/tests/trychange_unittest.py +++ b/tests/trychange_unittest.py @@ -40,7 +40,7 @@ class TryChangeUnittest(TryChangeTestsBase): """General trychange.py tests.""" def testMembersChanged(self): members = [ - 'EPILOG', 'EscapeDot', 'GIT', 'GuessVCS', 'GetMungedDiff', 'HELP_STRING', + 'EPILOG', 'Escape', 'GIT', 'GuessVCS', 'GetMungedDiff', 'HELP_STRING', 'InvalidScript', 'NoTryServerAccess', 'PrintSuccess', 'SCM', 'SVN', 'TryChange', 'USAGE', 'breakpad', 'datetime', 'errno', 'gcl', 'gclient_utils', 'getpass', diff --git a/trychange.py b/trychange.py index 602162369..5d73cb71d 100755 --- a/trychange.py +++ b/trychange.py @@ -85,8 +85,11 @@ class NoTryServerAccess(Exception): return self.args[0] + '\n' + HELP_STRING -def EscapeDot(name): - return name.replace('.', '-') +def Escape(name): + """Escapes characters that could interfere with the file system or try job + parsing. + """ + return re.sub(r'[^\w#-]', '_', name) class SCM(object): @@ -378,7 +381,7 @@ def _SendChangeSVN(options): # Diff file current_time = str(datetime.datetime.now()).replace(':', '.') - file_name = (EscapeDot(options.user) + '.' + EscapeDot(options.name) + + file_name = (Escape(options.user) + '.' + Escape(options.name) + '.%s.diff' % current_time) full_path = os.path.join(temp_dir, file_name) gclient_utils.FileWrite(full_path, options.diff, 'wb')