mirror of
https://github.com/esphome/esphome.git
synced 2024-11-22 15:08:10 +01:00
Fix error when using %% in printf format. (#1713)
For printf formatting, a check is done to see if the number of arguments matches the number of printf formatting placeholders. The escape code `%%` that is used for representing a literal `%` is also counted as a placeholder, but no argument will be provided for that one. This makes it impossible to use something like `("%f%%", percentage)` in the code. In such case, one gets the error: `Found 2 printf-patterns (%f, %%), but 1 args were given!` This commit fixes this behavior by omitting the `%%` from the matches. Co-authored-by: Maurice Makaay <mmakaay1@xs4all.net>
This commit is contained in:
parent
4250af4dd9
commit
7665a220a0
1 changed files with 1 additions and 3 deletions
|
@ -209,14 +209,12 @@ def validate_printf(value):
|
|||
cfmt = """\
|
||||
( # start of capture group 1
|
||||
% # literal "%"
|
||||
(?: # first option
|
||||
(?:[-+0 #]{0,5}) # optional flags
|
||||
(?:\d+|\*)? # width
|
||||
(?:\.(?:\d+|\*))? # precision
|
||||
(?:h|l|ll|w|I|I32|I64)? # size
|
||||
[cCdiouxXeEfgGaAnpsSZ] # type
|
||||
) | # OR
|
||||
%%) # literal "%%"
|
||||
)
|
||||
""" # noqa
|
||||
matches = re.findall(cfmt, value[CONF_FORMAT], flags=re.X)
|
||||
if len(matches) != len(value[CONF_ARGS]):
|
||||
|
|
Loading…
Reference in a new issue