From 3b0ea894c11140c1a0fabec9cf05c46e584e88a1 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 31 May 2016 00:21:14 +0200 Subject: [PATCH] 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. --- cpplint/cpplint.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cpplint/cpplint.py b/cpplint/cpplint.py index 9491320..a1b5642 100755 --- a/cpplint/cpplint.py +++ b/cpplint/cpplint.py @@ -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() + '_'