Skip to content

Commit 1b87fec

Browse files
committed
XWIKI-20365: Improved ClassEditSheet escaping
1 parent a0bd7ee commit 1b87fec

File tree

3 files changed

+118
-3
lines changed

3 files changed

+118
-3
lines changed

xwiki-platform-core/xwiki-platform-appwithinminutes/xwiki-platform-appwithinminutes-ui/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,12 @@
130130
<groupId>org.webjars</groupId>
131131
<artifactId>scriptaculous</artifactId>
132132
</dependency>
133+
<!-- Test dependencies. -->
134+
<dependency>
135+
<groupId>org.xwiki.platform</groupId>
136+
<artifactId>xwiki-platform-test-page</artifactId>
137+
<version>${project.version}</version>
138+
<scope>test</scope>
139+
</dependency>
133140
</dependencies>
134141
</project>

xwiki-platform-core/xwiki-platform-appwithinminutes/xwiki-platform-appwithinminutes-ui/src/main/resources/AppWithinMinutes/ClassEditSheet.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ xcontext.put('propertyCustomDisplayer', new PropertyCustomDisplayer(xcontext))
104104
#foreach ($category in $services.query.xwql($categoryListStatement).execute())
105105
#set ($categoryDoc = $xwiki.getDocument($category))
106106
&lt;li&gt;
107-
&lt;div class="category"&gt;$categoryDoc.plainTitle&lt;/div&gt;
107+
&lt;div class="category"&gt;$escapetool.xml($categoryDoc.plainTitle)&lt;/div&gt;
108108
#set ($formFieldsForCategoryStatement = "from doc.object($formFieldClassName) as field where field.category = :category order by field.priority")
109109
#set ($formFieldsForCategoryQuery = $services.query.xwql($formFieldsForCategoryStatement).bindValue('category', $category))
110110
&lt;ul&gt;
@@ -119,7 +119,7 @@ xcontext.put('propertyCustomDisplayer', new PropertyCustomDisplayer(xcontext))
119119
#else
120120
#set ($formFieldIconURL = $formFieldDoc.getAttachmentURL($formFieldIcon))
121121
#end
122-
#set ($formFieldIconRendered = "&lt;img src='$formFieldIconURL' alt='$escapetool.xml($formFieldDoc.plainTitle)' class='icon' /&gt;")
122+
#set ($formFieldIconRendered = "&lt;img src='$escapetool.xml($formFieldIconURL)' alt='$escapetool.xml($formFieldDoc.plainTitle)' class='icon' /&gt;")
123123
#end
124124
&lt;li class="field"&gt;
125125
$formFieldIconRendered
@@ -139,7 +139,7 @@ xcontext.put('propertyCustomDisplayer', new PropertyCustomDisplayer(xcontext))
139139
'field': $formFieldDoc.fullName,
140140
'xeditmode': 'text'
141141
})))
142-
&lt;input type="hidden" value="$fieldURL" class="data"/&gt;
142+
&lt;input type="hidden" value="$escapetool.xml($fieldURL)" class="data"/&gt;
143143
&lt;/li&gt;
144144
#end
145145
&lt;/ul&gt;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* See the NOTICE file distributed with this work for additional
3+
* information regarding copyright ownership.
4+
*
5+
* This is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU Lesser General Public License as
7+
* published by the Free Software Foundation; either version 2.1 of
8+
* the License, or (at your option) any later version.
9+
*
10+
* This software is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this software; if not, write to the Free
17+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19+
*/
20+
package org.xwikiplatform.appwithinminutes;
21+
22+
import java.util.List;
23+
24+
import org.jsoup.nodes.Document;
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Test;
27+
import org.mockito.Mock;
28+
import org.xwiki.groovy.internal.DefaultGroovyConfiguration;
29+
import org.xwiki.groovy.internal.GroovyScriptEngineFactory;
30+
import org.xwiki.model.reference.DocumentReference;
31+
import org.xwiki.query.Query;
32+
import org.xwiki.query.script.QueryManagerScriptService;
33+
import org.xwiki.rendering.internal.macro.groovy.GroovyMacro;
34+
import org.xwiki.rendering.syntax.Syntax;
35+
import org.xwiki.script.service.ScriptService;
36+
import org.xwiki.test.annotation.ComponentList;
37+
import org.xwiki.test.page.HTML50ComponentList;
38+
import org.xwiki.test.page.PageTest;
39+
import org.xwiki.test.page.XWikiSyntax21ComponentList;
40+
41+
import com.xpn.xwiki.doc.XWikiDocument;
42+
43+
import static org.junit.jupiter.api.Assertions.assertEquals;
44+
import static org.mockito.Mockito.when;
45+
46+
/**
47+
* Page Test of {@code AppWithinMinutes.ClassEditSheet}.
48+
*
49+
* @version $Id$
50+
* @since 14.4.8
51+
* @since 14.10.4
52+
* @since 15.0
53+
*/
54+
@HTML50ComponentList
55+
@XWikiSyntax21ComponentList
56+
@ComponentList({
57+
// Start GroovyMacro
58+
GroovyMacro.class,
59+
GroovyScriptEngineFactory.class,
60+
DefaultGroovyConfiguration.class
61+
// End GroovyMacro
62+
})
63+
class ClassEditSheetPageTest extends PageTest
64+
{
65+
private QueryManagerScriptService queryManagerScriptService;
66+
67+
@Mock
68+
private Query query;
69+
70+
@BeforeEach
71+
void setUp() throws Exception
72+
{
73+
this.queryManagerScriptService =
74+
this.componentManager.registerMockComponent(ScriptService.class, "query", QueryManagerScriptService.class,
75+
false);
76+
}
77+
78+
@Test
79+
void displayFieldPalette() throws Exception
80+
{
81+
loadPage(new DocumentReference("xwiki", "AppWithinMinutes", "VelocityMacros"));
82+
loadPage(new DocumentReference("xwiki", "AppWithinMinutes", "ClassEditSheet"));
83+
84+
when(this.queryManagerScriptService.xwql("from doc.object(AppWithinMinutes.FormFieldCategoryClass) as category "
85+
+ "order by category.priority")).thenReturn(this.query);
86+
when(this.query.execute()).thenReturn(List.of("xwiki:XWiki.Category"));
87+
88+
XWikiDocument xWikiDocumentCategory =
89+
this.xwiki.getDocument(new DocumentReference("xwiki", "XWiki", "Category"), this.context);
90+
xWikiDocumentCategory.setTitle("<strong>TITLE</strong>");
91+
this.xwiki.saveDocument(xWikiDocumentCategory, this.context);
92+
93+
XWikiDocument xwikiDocument =
94+
this.xwiki.getDocument(new DocumentReference("xwiki", "Space", "Page"), this.context);
95+
96+
xwikiDocument.setContent("{{include reference=\"AppWithinMinutes.ClassEditSheet\" /}}\n"
97+
+ "\n"
98+
+ "{{velocity}}\n"
99+
+ "#displayFieldPalette()\n"
100+
+ "{{/velocity}}\n");
101+
xwikiDocument.setSyntax(Syntax.XWIKI_2_1);
102+
this.xwiki.saveDocument(xwikiDocument, this.context);
103+
104+
Document document = renderHTMLPage(xwikiDocument);
105+
106+
assertEquals("<strong>TITLE</strong>", document.selectFirst(".category").text());
107+
}
108+
}

0 commit comments

Comments
 (0)