(original) (raw)
changeset: 105376:876bee0bd0ba parent: 105373:dc407f50e823 parent: 105375:306cfb866399 user: Łukasz Langa lukasz@langa.pl date: Sat Nov 26 14:04:40 2016 -0800 files: Misc/ACKS Misc/NEWS description: Merge 3.6, fix for #24142 diff -r dc407f50e823 -r 876bee0bd0ba Lib/configparser.py --- a/Lib/configparser.py Sat Nov 26 13:50:21 2016 +0200 +++ b/Lib/configparser.py Sat Nov 26 14:04:40 2016 -0800 @@ -1102,10 +1102,10 @@ # 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 -r dc407f50e823 -r 876bee0bd0ba Lib/test/test_configparser.py --- a/Lib/test/test_configparser.py Sat Nov 26 13:50:21 2016 +0200 +++ b/Lib/test/test_configparser.py Sat Nov 26 14:04:40 2016 -0800 @@ -9,6 +9,7 @@ from test import support + class SortedDict(collections.UserDict): def items(self): @@ -64,6 +65,7 @@ cf.read_string(string) return cf + class BasicTestCase(CfgParserTestCaseClass): def basic_test(self, cf): @@ -828,6 +830,21 @@ 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 @@ 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 @@ 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 @@ 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 ConfigParserTestCaseNoValue(ConfigParserTestCase): allow_no_value = True + class ConfigParserTestCaseTrickyFile(CfgParserTestCaseClass, unittest.TestCase): config_class = configparser.ConfigParser delimiters = {'='} diff -r dc407f50e823 -r 876bee0bd0ba Misc/ACKS --- a/Misc/ACKS Sat Nov 26 13:50:21 2016 +0200 +++ b/Misc/ACKS Sat Nov 26 14:04:40 2016 -0800 @@ -664,6 +664,7 @@ Ludwig Hähne Gerhard Häring Fredrik Håård +Florian Höch Catalin Iacob Mihai Ibanescu Ali Ikinci diff -r dc407f50e823 -r 876bee0bd0ba Misc/NEWS --- a/Misc/NEWS Sat Nov 26 13:50:21 2016 +0200 +++ b/Misc/NEWS Sat Nov 26 14:04:40 2016 -0800 @@ -409,6 +409,9 @@ - Issue #27972: Prohibit Tasks to await on themselves. +- Issue #24142: Reading a corrupt config file left configparser in an + invalid state. Original patch by Florian Höch. + Windows ------- /lukasz@langa.pl