2
0
Эх сурвалжийг харах

Merge branch 'raise-in-correct-place' of https://github.com/dandersson/dulwich

Jelmer Vernooij 7 жил өмнө
parent
commit
dd9de4d277

+ 2 - 0
NEWS

@@ -8,6 +8,8 @@
   * Raise an error when attempting to add paths that are not under the
     repository. (Jelmer Vernooij)
 
+  * Fix error message for missing trailing ]. (Daniel Andersson)
+
   IMPROVEMENTS
 
   * Enforce date field parsing consistency. This also add checks on

+ 3 - 2
dulwich/config.py

@@ -283,8 +283,9 @@ class ConfigFile(ConfigDict):
                 # Parse section header ("[bla]")
                 if len(line) > 0 and line[:1] == b"[":
                     line = _strip_comments(line).rstrip()
-                    last = line.index(b"]")
-                    if last == -1:
+                    try:
+                        last = line.index(b"]")
+                    except ValueError:
                         raise ValueError("expected trailing ]")
                     pts = line[1:last].split(b" ", 1)
                     line = line[last+1:]

+ 4 - 1
dulwich/tests/test_config.py

@@ -95,7 +95,10 @@ class ConfigFileTests(TestCase):
         cf = self.from_file(b"[core]\nfoo = \"bar\"la\n")
         self.assertEqual(b"barla", cf.get((b"core", ), b"foo"))
 
-    def test_from_file_with_open_quoted(self):
+    def test_from_file_section_with_open_brackets(self):
+        self.assertRaises(ValueError, self.from_file, b"[core\nfoo = bar\n")
+
+    def test_from_file_value_with_open_quoted(self):
         self.assertRaises(ValueError, self.from_file, b"[core]\nfoo = \"bar\n")
 
     def test_from_file_with_quotes(self):