Message364688
There is an inconsistency in re.sub() when substituting at the end of a string using a prior match with a '*' qualifier: the substitution now occurs twice. For example:
txt = re.sub(r'\s*\Z', "\n", txt)
This should work like txt.rstrip() + "\n", but beginning in 3.7, the re.sub version now matches twice and changes any non-empty whitespace into "\n\n" instead of "\n". (If there is no trailing whitespace it only matches once.)
The bug is the same if '$' is used instead of '\Z', but it does not happen if an actual character is specified (e.g. a substitution of r'\s*x' does not substitute twice if x has preceding whitespace).
I tested 2.7.17, 3.6.9, 3.7.7, 3.8.2, and 3.9.0a4, and it starts to fail in 3.7.7 and beyond.
Attached is a test program. |
|
Date |
User |
Action |
Args |
2020-03-20 17:21:13 | WayneD | set | recipients:
+ WayneD, ezio.melotti, mrabarnett |
2020-03-20 17:21:13 | WayneD | set | messageid: <1584724873.49.0.294512015302.issue40027@roundup.psfhosted.org> |
2020-03-20 17:21:13 | WayneD | link | issue40027 messages |
2020-03-20 17:21:13 | WayneD | create | |
|