pre-upload: Add a check for FilePath::FromUTF8Unsafe stuff
FromUTF8Unsafe() and AsUTF8Unsafe() are not necessary in places
like platform2 since it's safe to assume file names are UTF-8 on
Chrome OS. We can use FilePath() and value() instead.
BUG=chromium:870621
TEST=./pre-upload_unittest.py
Change-Id: I688b893a8b7477ec4499dd4b093a7733a3f9dc5d
Reviewed-on: https://chromium-review.googlesource.com/1166273
Commit-Ready: Satoru Takabayashi <satorux@google.com>
Tested-by: Satoru Takabayashi <satorux@google.com>
Reviewed-by: Dan Erat <derat@chromium.org>
diff --git a/pre-upload.py b/pre-upload.py
index 5f87a8e..c923463 100755
--- a/pre-upload.py
+++ b/pre-upload.py
@@ -1446,6 +1446,8 @@
FILEPATH_REGEXP = re.compile('|'.join(
[r'(?:base::)?FilePath::(?:Char|String|StringPiece)Type',
+ r'(?:base::)?FilePath::FromUTF8Unsafe',
+ r'AsUTF8Unsafe',
r'FILE_PATH_LITERAL']))
files = _filter_files(_get_affected_files(commit, relative=True),
[r'.*\.(cc|h)$'])
diff --git a/pre-upload_unittest.py b/pre-upload_unittest.py
index d97f506..4091fca 100755
--- a/pre-upload_unittest.py
+++ b/pre-upload_unittest.py
@@ -202,10 +202,13 @@
(2, 'base::FilePath::CharType'), # NG
(3, 'base::FilePath::StringType'), # NG
(4, 'base::FilePath::StringPieceType'), # NG
- (5, 'FilePath::CharType'), # NG
- (6, 'FilePath::StringType'), # NG
- (7, 'FilePath::StringPieceType'), # NG
- (8, 'FILE_PATH_LITERAL'), # NG
+ (5, 'base::FilePath::FromUTF8Unsafe'), # NG
+ (6, 'FilePath::CharType'), # NG
+ (7, 'FilePath::StringType'), # NG
+ (8, 'FilePath::StringPieceType'), # NG
+ (9, 'FilePath::FromUTF8Unsafe'), # NG
+ (10, 'AsUTF8Unsafe'), # NG
+ (11, 'FILE_PATH_LITERAL'), # NG
]
failure = pre_upload._check_filepath_chartype(ProjectNamed('PROJECT'),
'COMMIT')
@@ -216,10 +219,13 @@
self.assertEquals(['x.cc, line 2 has base::FilePath::CharType',
'x.cc, line 3 has base::FilePath::StringType',
'x.cc, line 4 has base::FilePath::StringPieceType',
- 'x.cc, line 5 has FilePath::CharType',
- 'x.cc, line 6 has FilePath::StringType',
- 'x.cc, line 7 has FilePath::StringPieceType',
- 'x.cc, line 8 has FILE_PATH_LITERAL'],
+ 'x.cc, line 5 has base::FilePath::FromUTF8Unsafe',
+ 'x.cc, line 6 has FilePath::CharType',
+ 'x.cc, line 7 has FilePath::StringType',
+ 'x.cc, line 8 has FilePath::StringPieceType',
+ 'x.cc, line 9 has FilePath::FromUTF8Unsafe',
+ 'x.cc, line 10 has AsUTF8Unsafe',
+ 'x.cc, line 11 has FILE_PATH_LITERAL'],
failure.items)