[Python-checkins] bpo-38741: Definition of multiple ']' in header configparser (GH-17129)

ambv webhook-mailer at python.org
Tue Jul 13 09:54:18 EDT 2021


https://github.com/python/cpython/commit/2924bb1a566977efd45f335d6a94cd84d8047edf
commit: 2924bb1a566977efd45f335d6a94cd84d8047edf
branch: main
author: jsnklln <jsnklln at gmail.com>
committer: ambv <lukasz at langa.pl>
date: 2021-07-13T15:54:06+02:00
summary:

bpo-38741: Definition of multiple ']' in header configparser (GH-17129)

Co-authored-by: Jason Killen <jason.killen at windsorcircle.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>

files:
A Misc/NEWS.d/next/Library/2019-11-12-18-59-33.bpo-38741.W7IYkq.rst
M Lib/configparser.py
M Lib/test/test_configparser.py

diff --git a/Lib/configparser.py b/Lib/configparser.py
index 2f45e242b4942..042a5c74b696f 100644
--- a/Lib/configparser.py
+++ b/Lib/configparser.py
@@ -563,7 +563,7 @@ class RawConfigParser(MutableMapping):
     # Regular expressions for parsing section headers and options
     _SECT_TMPL = r"""
         \[                                 # [
-        (?P<header>[^]]+)                  # very permissive!
+        (?P<header>.+)                     # very permissive!
         \]                                 # ]
         """
     _OPT_TMPL = r"""
diff --git a/Lib/test/test_configparser.py b/Lib/test/test_configparser.py
index 9373a62072ef4..e9b03e6c62ef1 100644
--- a/Lib/test/test_configparser.py
+++ b/Lib/test/test_configparser.py
@@ -79,6 +79,7 @@ def basic_test(self, cf):
              'Spacey Bar',
              'Spacey Bar From The Beginning',
              'Types',
+             'This One Has A ] In It',
              ]
 
         if self.allow_no_value:
@@ -130,6 +131,7 @@ def basic_test(self, cf):
         eq(cf.get('Types', 'float'), "0.44")
         eq(cf.getboolean('Types', 'boolean'), False)
         eq(cf.get('Types', '123'), 'strange but acceptable')
+        eq(cf.get('This One Has A ] In It', 'forks'), 'spoons')
         if self.allow_no_value:
             eq(cf.get('NoValue', 'option-without-value'), None)
 
@@ -320,6 +322,8 @@ def test_basic(self):
 float {0[0]} 0.44
 boolean {0[0]} NO
 123 {0[1]} strange but acceptable
+[This One Has A ] In It]
+  forks {0[0]} spoons
 """.format(self.delimiters, self.comment_prefixes)
         if self.allow_no_value:
             config_string += (
@@ -394,6 +398,9 @@ def test_basic_from_dict(self):
                 "boolean": False,
                 123: "strange but acceptable",
             },
+            "This One Has A ] In It": {
+                "forks": "spoons"
+            },
         }
         if self.allow_no_value:
             config.update({
diff --git a/Misc/NEWS.d/next/Library/2019-11-12-18-59-33.bpo-38741.W7IYkq.rst b/Misc/NEWS.d/next/Library/2019-11-12-18-59-33.bpo-38741.W7IYkq.rst
new file mode 100644
index 0000000000000..39d84ccea55b8
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-11-12-18-59-33.bpo-38741.W7IYkq.rst
@@ -0,0 +1 @@
+:mod:`configparser`: using ']' inside a section header will no longer cut the section name short at the ']'
\ No newline at end of file



More information about the Python-checkins mailing list