changeset 1264:7275fd6533b2

fix internal server error on circular transclusion loop, enhance error message, fixes issue #80
author Roger Haase <crosseyedpenguin@yahoo.com>
date Tue, 14 Feb 2012 10:48:43 -0700
parents 65d36909177b
children cb2f379e0c19
files MoinMoin/converter/_tests/test_include.py MoinMoin/converter/include.py
diffstat 2 files changed, 13 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/converter/_tests/test_include.py	Fri Feb 03 15:14:28 2012 +0100
+++ b/MoinMoin/converter/_tests/test_include.py	Tue Feb 14 10:48:43 2012 -0700
@@ -65,10 +65,11 @@
 
     def test_IncludeHandlesCircularRecursion(self):
         # issue #80
-        # we choosed MoinWiki items so tests get simpler
+        # we use MoinWiki items to make tests simple
         update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'{{page2}}')
         update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u'{{page3}}')
-        update_item(u'page3', {CONTENTTYPE: u'text/x.moin.wiki'}, u'{{page1}}')
+        update_item(u'page3', {CONTENTTYPE: u'text/x.moin.wiki'}, u'{{page4}}')
+        update_item(u'page4', {CONTENTTYPE: u'text/x.moin.wiki'}, u'{{page2}}')
 
         page1 = MoinWiki.create(u'page1')
 
--- a/MoinMoin/converter/include.py	Fri Feb 03 15:14:28 2012 +0100
+++ b/MoinMoin/converter/include.py	Tue Feb 14 10:48:43 2012 -0700
@@ -219,12 +219,15 @@
                     pages = ((Item.create(p), Iri(scheme='wiki', authority='', path='/' + p)) for p in pagelist)
 
                 included_elements = []
-                for page, page_href in pages:
-                    if page_href.path[0] != '/':
-                        page_href.path = IriPath('/' + '/'.join(page_href.path))
-                    if page_href in self.stack:
+                for page, p_href in pages:
+                    if p_href.path[0] != '/':
+                        p_href.path = IriPath('/' + '/'.join(p_href.path))
+                    if p_href in self.stack:
+                        # we have a transclusion loop, create an error message showing list of pages forming loop
+                        loop = self.stack[self.stack.index(p_href):]
+                        loop = [u'{0}'.format(ref.path[1:]) for ref in loop if ref is not None] + [page.name]
+                        msg = u'Error: Transclusion loop via: ' + u', '.join(loop)
                         attrib = {getattr(html, 'class'): 'error'}
-                        msg = 'Recursive include of "{0}" forbidden'.format(page.name)
                         strong = ET.Element(html.strong, attrib, (msg, ))
                         included_elements.append(strong)
                         continue
@@ -233,7 +236,7 @@
                         continue
 
                     if xp_include_heading is not None:
-                        attrib = {self.tag_href: page_href}
+                        attrib = {self.tag_href: p_href}
                         children = (xp_include_heading or page.name, )
                         elem_a = ET.Element(self.tag_a, attrib, children=children)
                         attrib = {self.tag_outline_level: xp_include_level or '1'}
@@ -246,7 +249,7 @@
                     # Wrap the page with the overlay, but only if it's a "page", or "a".
                     # The href needs to be an absolute URI, without the prefix "wiki://"
                     if page_doc.tag.endswith("page") or page_doc.tag.endswith("a"):
-                        page_doc = wrap_object_with_overlay(page_doc, href=unicode(page_href.path))
+                        page_doc = wrap_object_with_overlay(page_doc, href=unicode(p_href.path))
 
                     included_elements.append(page_doc)