Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1369)

Side by Side Diff: patch.py

Issue 1160663007: Fix filename checks (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Addressed review comments Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # coding=utf8 1 # coding=utf8
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 """Utility functions to handle patches.""" 5 """Utility functions to handle patches."""
6 6
7 import posixpath 7 import posixpath
8 import os 8 import os
9 import re 9 import re
10 10
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 return self.source_filename.encode('utf-8') 47 return self.source_filename.encode('utf-8')
48 48
49 @staticmethod 49 @staticmethod
50 def _process_filename(filename): 50 def _process_filename(filename):
51 filename = filename.replace('\\', '/') 51 filename = filename.replace('\\', '/')
52 # Blacklist a few characters for simplicity. 52 # Blacklist a few characters for simplicity.
53 for i in ('$', '..', '\'', '"', '<', '>', ':', '|', '?', '*'): 53 for i in ('$', '..', '\'', '"', '<', '>', ':', '|', '?', '*'):
54 if i in filename: 54 if i in filename:
55 raise UnsupportedPatchFormat( 55 raise UnsupportedPatchFormat(
56 filename, 'Can\'t use \'%s\' in filename.' % i) 56 filename, 'Can\'t use \'%s\' in filename.' % i)
57 for i in ('/', 'CON', 'COM'): 57 if filename.startswith('/'):
58 if filename.startswith(i): 58 raise UnsupportedPatchFormat(
59 raise UnsupportedPatchFormat( 59 filename, 'Filename can\'t start with \'/\'.')
60 filename, 'Filename can\'t start with \'%s\'.' % i) 60 if filename == 'CON':
61 raise UnsupportedPatchFormat(
62 filename, 'Filename can\'t be \'CON\'.')
63 if re.match('COM\d', filename):
64 raise UnsupportedPatchFormat(
65 filename, 'Filename can\'t be \'%s\'.' % filename)
61 return filename 66 return filename
62 67
63 def set_relpath(self, relpath): 68 def set_relpath(self, relpath):
64 if not relpath: 69 if not relpath:
65 return 70 return
66 relpath = relpath.replace('\\', '/') 71 relpath = relpath.replace('\\', '/')
67 if relpath[0] == '/': 72 if relpath[0] == '/':
68 self._fail('Relative path starts with %s' % relpath[0]) 73 self._fail('Relative path starts with %s' % relpath[0])
69 self.filename = self._process_filename( 74 self.filename = self._process_filename(
70 posixpath.join(relpath, self.filename)) 75 posixpath.join(relpath, self.filename))
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 def __iter__(self): 539 def __iter__(self):
535 for patch in self.patches: 540 for patch in self.patches:
536 yield patch 541 yield patch
537 542
538 def __getitem__(self, key): 543 def __getitem__(self, key):
539 return self.patches[key] 544 return self.patches[key]
540 545
541 @property 546 @property
542 def filenames(self): 547 def filenames(self):
543 return [p.filename for p in self.patches] 548 return [p.filename for p in self.patches]
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698