On Nov 30, 2010, at 4:16 PM, tmortagne (SVN) wrote:
Author: tmortagne
Date: 2010-11-30 16:16:46 +0100 (Tue, 30 Nov 2010)
New Revision: 33194
Modified:
platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java
platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/doc/XWikiDocumentRenderingTest.java
Log:
XWIKI-4771: Cycles in the method Document.getDisplayTitle are not detected
Modified:
platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java
===================================================================
---
platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java 2010-11-30
15:00:36 UTC (rev 33193)
+++
platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java 2010-11-30
15:16:46 UTC (rev 33194)
@@ -43,6 +43,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.Stack;
import java.util.TreeMap;
import java.util.Vector;
import java.util.regex.Matcher;
@@ -1203,7 +1204,20 @@
private String getRenderedContentTitle(Syntax outputSyntax, XWikiContext context)
throws XWikiException
{
String title = null;
+
This code below requires comment to understand it. It's not obvious to understand
it's to prevent cycles. Might be also good to put it in a separate method to make it
even more clear.
I also think the pop should be in a finally block.
Thanks
-Vincent
+ Stack<DocumentReference> stackTrace =
+ (Stack<DocumentReference>)
context.get("internal.getRenderedContentTitleStackTrace");
+ if (stackTrace == null) {
+ stackTrace = new Stack<DocumentReference>();
+ context.put("internal.getRenderedContentTitleStackTrace",
stackTrace);
+ } else if (stackTrace.contains(getDocumentReference())) {
+ // TODO: generate an error message instead ?
+ return null;
+ }
+
+ stackTrace.push(getDocumentReference());
+
if (is10Syntax()) {
title = getRenderedContentTitle10(context);
} else {
@@ -1235,6 +1249,8 @@
}
}
+ stackTrace.pop();
+
return title;
}
Modified:
platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/doc/XWikiDocumentRenderingTest.java
===================================================================
---
platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/doc/XWikiDocumentRenderingTest.java 2010-11-30
15:00:36 UTC (rev 33193)
+++
platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/doc/XWikiDocumentRenderingTest.java 2010-11-30
15:16:46 UTC (rev 33194)
@@ -250,7 +250,18 @@
assertEquals("Page", this.document.getRenderedTitle(Syntax.XHTML_1_0,
getContext()));
}
+
+ /**
+ * Make sure title extracted from content is protected from cycles
+ */
+ public void testGetRenderedTitleRecursive() throws XWikiException
+ {
+ this.document.setSyntax(Syntax.XWIKI_2_0);
+ this.document.setContent("= {{groovy}}print
doc.getDisplayTitle(){{/groovy}}");
+ assertEquals("Page", this.document.getRenderedTitle(Syntax.XHTML_1_0,
getContext()));
+ }
+
public void testExtractTitle()
{
this.document.setSyntaxId("xwiki/2.0");
____________________________________