Using percent signs with SafeConfigParser
Peter Otten
__peter__ at web.de
Sat Apr 11 15:06:52 EDT 2009
Márcio Faustino wrote:
> Does the SafeConfigParser class correctly detects lone percent signs?
> For example, shouldn't the string "100%%" be accepted as a valid
> value? Executing the code below should only print one error, instead
> it prints 2. (I've tested this with version 2.6.1 on Windows XP.)
>
> It seems the "_badpercent_re" regular expression (an attribute of
> SafeConfigParser, with value "%[^%]|%$") is flawed:
> - The first alternative "%[^%]" fails with the string "%%_", because
> it matches "%_".
> - The second alternative "%$" fails with the string "%%", because it
> matches "%".
I think you are right. Please file a bug report .
> The correct regular expression is "(?<!%)%(?!%)", which passes the
> previous tests.
IMO this doesn't fix the problem because
(1) it allows "%%%" which is also incorrect
(2) _interpvar_re has already butchered values like "%%(alpha)s" to "%"
Peter
More information about the Python-list
mailing list