summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorŁukasz Langa <lukasz@langa.pl>2016-11-26 22:02:48 (GMT)
committerŁukasz Langa <lukasz@langa.pl>2016-11-26 22:02:48 (GMT)
commit8fb4e421f41bda398e7d6e1f56b22d912609dc17 (patch)
tree2ed75ac39df19c04677bb6d623569d1c1111b1c6
parent0264e46caa854803a5318d75ae7893e9174f3f70 (diff)
parent47a9a4bedaa343e72898b2c7534d27f3e0cf4ff5 (diff)
downloadcpython-8fb4e421f41bda398e7d6e1f56b22d912609dc17.zip
cpython-8fb4e421f41bda398e7d6e1f56b22d912609dc17.tar.gz
cpython-8fb4e421f41bda398e7d6e1f56b22d912609dc17.tar.bz2
Merge 3.5, fix for #24142
-rw-r--r--Lib/configparser.py2
-rw-r--r--Lib/test/test_configparser.py24
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS3
4 files changed, 29 insertions, 1 deletions
diff --git a/Lib/configparser.py b/Lib/configparser.py
index 3a9fb56..af5aca1 100644
--- a/Lib/configparser.py
+++ b/Lib/configparser.py
@@ -1102,10 +1102,10 @@ class RawConfigParser(MutableMapping):
# raised at the end of the file and will contain a
# list of all bogus lines
e = self._handle_error(e, fpname, lineno, line)
+ self._join_multiline_values()
# if any parsing errors occurred, raise an exception
if e:
raise e
- self._join_multiline_values()
def _join_multiline_values(self):
defaults = self.default_section, self._defaults
diff --git a/Lib/test/test_configparser.py b/Lib/test/test_configparser.py
index 2b08198..0d06080 100644
--- a/Lib/test/test_configparser.py
+++ b/Lib/test/test_configparser.py
@@ -9,6 +9,7 @@ import warnings
from test import support
+
class SortedDict(collections.UserDict):
def items(self):
@@ -64,6 +65,7 @@ class CfgParserTestCaseClass:
cf.read_string(string)
return cf
+
class BasicTestCase(CfgParserTestCaseClass):
def basic_test(self, cf):
@@ -828,6 +830,21 @@ boolean {0[0]} NO
self.assertEqual(set(cf['section3'].keys()), set())
self.assertEqual(cf.sections(), ['section1', 'section2', 'section3'])
+ def test_invalid_multiline_value(self):
+ if self.allow_no_value:
+ self.skipTest('if no_value is allowed, ParsingError is not raised')
+
+ invalid = textwrap.dedent("""\
+ [DEFAULT]
+ test {0} test
+ invalid""".format(self.delimiters[0])
+ )
+ cf = self.newconfig()
+ with self.assertRaises(configparser.ParsingError):
+ cf.read_string(invalid)
+ self.assertEqual(cf.get('DEFAULT', 'test'), 'test')
+ self.assertEqual(cf['DEFAULT']['test'], 'test')
+
class StrictTestCase(BasicTestCase, unittest.TestCase):
config_class = configparser.RawConfigParser
@@ -981,14 +998,17 @@ class ConfigParserTestCaseLegacyInterpolation(ConfigParserTestCase):
cf.set("sect", "option2", "foo%%bar")
self.assertEqual(cf.get("sect", "option2"), "foo%%bar")
+
class ConfigParserTestCaseNonStandardDelimiters(ConfigParserTestCase):
delimiters = (':=', '$')
comment_prefixes = ('//', '"')
inline_comment_prefixes = ('//', '"')
+
class ConfigParserTestCaseNonStandardDefaultSection(ConfigParserTestCase):
default_section = 'general'
+
class MultilineValuesTestCase(BasicTestCase, unittest.TestCase):
config_class = configparser.ConfigParser
wonderful_spam = ("I'm having spam spam spam spam "
@@ -1017,6 +1037,7 @@ class MultilineValuesTestCase(BasicTestCase, unittest.TestCase):
self.assertEqual(cf_from_file.get('section8', 'lovely_spam4'),
self.wonderful_spam.replace('\t\n', '\n'))
+
class RawConfigParserTestCase(BasicTestCase, unittest.TestCase):
config_class = configparser.RawConfigParser
@@ -1059,11 +1080,13 @@ class RawConfigParserTestCase(BasicTestCase, unittest.TestCase):
cf.set('non-string', 1, 1)
self.assertEqual(cf.get('non-string', 1), 1)
+
class RawConfigParserTestCaseNonStandardDelimiters(RawConfigParserTestCase):
delimiters = (':=', '$')
comment_prefixes = ('//', '"')
inline_comment_prefixes = ('//', '"')
+
class RawConfigParserTestSambaConf(CfgParserTestCaseClass, unittest.TestCase):
config_class = configparser.RawConfigParser
comment_prefixes = ('#', ';', '----')
@@ -1258,6 +1281,7 @@ class ConfigParserTestCaseExtendedInterpolation(BasicTestCase, unittest.TestCase
class ConfigParserTestCaseNoValue(ConfigParserTestCase):
allow_no_value = True
+
class ConfigParserTestCaseTrickyFile(CfgParserTestCaseClass, unittest.TestCase):
config_class = configparser.ConfigParser
delimiters = {'='}
diff --git a/Misc/ACKS b/Misc/ACKS
index 35b6b7d..2a3a278 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -663,6 +663,7 @@ Jeremy Hylton
Ludwig Hähne
Gerhard Häring
Fredrik Håård
+Florian Höch
Catalin Iacob
Mihai Ibanescu
Ali Ikinci
diff --git a/Misc/NEWS b/Misc/NEWS
index 929ce53..c950383 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -17,6 +17,9 @@ Core and Builtins
Library
-------
+- Issue #24142: Reading a corrupt config file left configparser in an
+ invalid state. Original patch by Florian Höch.
+
Tools/Demos
-----------