mirror of
https://github.com/google/styleguide.git
synced 2024-03-22 13:11:43 +08:00
Fix regex escape issue when using --root on Windows
The code was using directory separator in the regex itself, which means on Windows it was leaving unescaped backslash. Added explicit escape for such cases.
This commit is contained in:
parent
70d6b7d4b8
commit
3b0ea894c1
7
cpplint/cpplint.py
vendored
7
cpplint/cpplint.py
vendored
|
@ -1746,7 +1746,12 @@ def GetHeaderGuardCPPVariable(filename):
|
||||||
fileinfo = FileInfo(filename)
|
fileinfo = FileInfo(filename)
|
||||||
file_path_from_root = fileinfo.RepositoryName()
|
file_path_from_root = fileinfo.RepositoryName()
|
||||||
if _root:
|
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() + '_'
|
return re.sub(r'[^a-zA-Z0-9]', '_', file_path_from_root).upper() + '_'
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user