Skip to content

Commit 8b6a216

Browse files
DelganFlorianWilhelm
authored andcommitted
Fix square brackets not parsed in section names
1 parent 09d88d0 commit 8b6a216

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/configupdater/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class Parser:
117117
# Regular expressions for parsing section headers and options
118118
_SECT_TMPL: str = r"""
119119
\[ # [
120-
(?P<header>[^]]+) # very permissive!
120+
(?P<header>.+) # very permissive!
121121
\] # ]
122122
(?P<raw_comment>.*) # match any suffix
123123
"""

tests/test_configupdater.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,3 +1589,16 @@ def test_no_change_but_option2_fixed(cfg, exp_cfg, prepend_newline):
15891589
options, prepend_newline=False, indent=2 * " "
15901590
)
15911591
assert str(updater) == dedent(exp_cfg_no_newline_indent2)
1592+
1593+
1594+
def test_parsing_of_brackets_in_section_names():
1595+
cfg = """\
1596+
[ ]
1597+
[[]]
1598+
[][]
1599+
[]#]#
1600+
"""
1601+
cfg = dedent(cfg)
1602+
updater = ConfigUpdater()
1603+
updater.read_string(cfg)
1604+
assert updater.sections() == [" ", "[]", "][", "]#"]

0 commit comments

Comments
 (0)