Merge pull request #139 from Nazg-Gul/root_windows_fix

Fix regex escape issue when using --root on Windows
This commit is contained in:
Elliot Glaysher 2016-06-30 13:20:33 -07:00 committed by GitHub
commit 450aa460ec

7
cpplint/cpplint.py vendored
View File

@ -1746,7 +1746,12 @@ def GetHeaderGuardCPPVariable(filename):
fileinfo = FileInfo(filename)
file_path_from_root = fileinfo.RepositoryName()
if _root:
file_path_from_root = re.sub('^' + _root + os.sep, '', file_path_from_root)
suffix = os.sep
# On Windows using directory separator will leave us with
# "bogus escape error" unless we properly escape regex.
if suffix == '\\':
suffix += '\\'
file_path_from_root = re.sub('^' + _root + suffix, '', file_path_from_root)
return re.sub(r'[^a-zA-Z0-9]', '_', file_path_from_root).upper() + '_'