Commits

Luke Plant committed b0f6c53

Ensure we don't have duplicate ids for sections

Comments (0)

Files changed (2)

semanticeditor/tests.py

         self.assertEqual(structure[0].sect_id, "h1_10")
         self.assertEqual(structure[1].sect_id, "h1_1")
 
+    def test_dont_use_duplicate_existing_sect_id(self):
+        html = "<h1 id='h1_10'>Hi</h1><h1 id='h1_10'>There</h1>"
+        structure = get_structure(parse(html))
+        self.assertEqual(structure[0].sect_id, "h1_10")
+        self.assertEqual(structure[1].sect_id, "h1_1")
+
 class TestPresentationInfo(TestCase):
     def test_equality(self):
         p1 = PresentationInfo(prestype="command", name="foo", verbose_name="blah")

semanticeditor/utils/presentation.py

         if n.tag in blockdef:
             text = flatten(n)
             sect_id = n.get('id', '')
-            if sect_id == '' or not sect_id.startswith(n.tag):
+            if sect_id == '' or not sect_id.startswith(n.tag) or sect_id in sect_ids:
                 sect_id = make_sect_id(n.tag, sect_ids)
             sect_ids.add(sect_id)
             if n.tag in headingdef: