Commit b88569e
committed
gh-157456: Fix configparser parsing an empty value with a whitespace-ending delimiter
An option whose delimiter ends in whitespace (e.g. ``delimiters=(' ',)``) and
has an empty value could not be parsed, and the parser could not read back the
output produced by ``write()``: ``_read`` matched option lines against
``line.clean``, which is ``str.strip``-ed on both sides, so for a whitespace
delimiter the trailing whitespace that separates the key from the (empty) value
was removed and ``OPTCRE`` no longer matched.
Match the option regex against a form that preserves trailing whitespace. The
matched value is stripped immediately afterwards, so ordinary values keep no
trailing whitespace, and the other uses of ``line.clean`` are unchanged.
Add a regression test; the gh-156353 whitespace-delimiter tests only used
non-empty values, so this edge was unpinned.1 parent fb46c67 commit b88569e
3 files changed
Lines changed: 31 additions & 3 deletions
File tree
- Lib
- test
- Misc/NEWS.d/next/Library
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
599 | 599 | | |
600 | 600 | | |
601 | 601 | | |
602 | | - | |
603 | | - | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
604 | 605 | | |
605 | 606 | | |
606 | 607 | | |
| |||
1156 | 1157 | | |
1157 | 1158 | | |
1158 | 1159 | | |
1159 | | - | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
1160 | 1167 | | |
1161 | 1168 | | |
1162 | 1169 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
385 | 385 | | |
386 | 386 | | |
387 | 387 | | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
388 | 405 | | |
389 | 406 | | |
390 | 407 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
0 commit comments