From df7784bd1c8495eef50e1102b5b36ab7420944d3 Mon Sep 17 00:00:00 2001 From: Jason Killen Date: Tue, 12 Nov 2019 13:26:46 -0500 Subject: [PATCH 1/3] bpo-38741: Definition of multiple ']' in header configparser I've changed up the regex for finding section headers. I don't know if this covers every case but it covers all the cases I could come up with. The docs don't really call out if ] should be allowed in section headers but I can't think of any reason it shouldn't be. This change keeps the existing failure if you try and define a section with no name, like []. --- Lib/configparser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/configparser.py b/Lib/configparser.py index 924cc56a3f150d..e5bf8b6c1dfdcb 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
[^]]+) # very permissive! + (?P
.+) # very permissive! \] # ] """ _OPT_TMPL = r""" From 8f9c53000c16152e5c31d4b5ec40a3c49bb203de Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Tue, 12 Nov 2019 18:59:34 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NEWS.d/next/Library/2019-11-12-18-59-33.bpo-38741.W7IYkq.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2019-11-12-18-59-33.bpo-38741.W7IYkq.rst 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 00000000000000..39d84ccea55b8c --- /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 From fa270a6437ffd9c7e790a61902b9ff9315a44275 Mon Sep 17 00:00:00 2001 From: Jason Killen Date: Wed, 13 Nov 2019 11:19:24 -0500 Subject: [PATCH 3/3] Added tests to ensure sections with ] in them are read correctly. Included a check for key=value because the original issue mentioned that it might not be working. --- Lib/test/test_configparser.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Lib/test/test_configparser.py b/Lib/test/test_configparser.py index f16da116a745f3..9e9be5820b2f0f 100644 --- a/Lib/test/test_configparser.py +++ b/Lib/test/test_configparser.py @@ -78,6 +78,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: @@ -129,6 +130,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) @@ -319,6 +321,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 += ( @@ -393,6 +397,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({