Skip to content

Commit 18857b4

Browse files
author
MarcoFalke
committed
Merge #14960: lint/format-strings: Correctly exclude escaped percent symbols
5728119 lint/format-strings: Correctly exclude escaped percent symbols (Luke Dashjr) Pull request description: The current code fails to exclude correctly for patterns like `"%%%X"` Tree-SHA512: cac6f6fb3f06a9190310cd9764ec31cd7d636f9c831057622f418ae5fd2e1d80927a88f585d18f57b279ac21e81518f714dc1a25155377b9297741a73600461e
2 parents 1ac7d59 + 5728119 commit 18857b4

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

test/lint/lint-format-strings.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,11 @@ def count_format_specifiers(format_string):
241241
4
242242
"""
243243
assert(type(format_string) is str)
244+
format_string = format_string.replace('%%', 'X')
244245
n = 0
245246
in_specifier = False
246247
for i, char in enumerate(format_string):
247-
if format_string[i - 1:i + 1] == "%%" or format_string[i:i + 2] == "%%":
248-
pass
249-
elif char == "%":
248+
if char == "%":
250249
in_specifier = True
251250
n += 1
252251
elif char in "aAcdeEfFgGinopsuxX":

0 commit comments

Comments
 (0)