Skip to content

Commit 3b0ea89

Browse files
committed
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.
1 parent 70d6b7d commit 3b0ea89

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

cpplint/cpplint.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1746,7 +1746,12 @@ def GetHeaderGuardCPPVariable(filename):
17461746
fileinfo = FileInfo(filename)
17471747
file_path_from_root = fileinfo.RepositoryName()
17481748
if _root:
1749-
file_path_from_root = re.sub('^' + _root + os.sep, '', file_path_from_root)
1749+
suffix = os.sep
1750+
# On Windows using directory separator will leave us with
1751+
# "bogus escape error" unless we properly escape regex.
1752+
if suffix == '\\':
1753+
suffix += '\\'
1754+
file_path_from_root = re.sub('^' + _root + suffix, '', file_path_from_root)
17501755
return re.sub(r'[^a-zA-Z0-9]', '_', file_path_from_root).upper() + '_'
17511756

17521757

0 commit comments

Comments
 (0)