-
-
Notifications
You must be signed in to change notification settings - Fork 552
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
XWIKI-21810: Improve suggest URL escaping in StringClass
(cherry picked from commit ec18f3a)
- Loading branch information
1 parent
7e238f5
commit 27eca84
Showing
2 changed files
with
120 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...e/xwiki-platform-oldcore/src/test/java/com/xpn/xwiki/objects/classes/StringClassTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package com.xpn.xwiki.objects.classes; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mock; | ||
import org.xwiki.model.reference.DocumentReference; | ||
|
||
import com.xpn.xwiki.XWikiContext; | ||
import com.xpn.xwiki.test.MockitoOldcore; | ||
import com.xpn.xwiki.test.component.XWikiDocumentFilterUtilsComponentList; | ||
import com.xpn.xwiki.test.junit5.mockito.InjectMockitoOldcore; | ||
import com.xpn.xwiki.test.junit5.mockito.OldcoreTest; | ||
import com.xpn.xwiki.web.XWikiURLFactory; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.when; | ||
|
||
/** | ||
* Test of {@link StringClass}. | ||
* | ||
* @version $Id$ | ||
*/ | ||
@OldcoreTest | ||
@XWikiDocumentFilterUtilsComponentList | ||
class StringClassTest | ||
{ | ||
@InjectMockitoOldcore | ||
private MockitoOldcore oldCore; | ||
|
||
@Mock | ||
private XWikiURLFactory urlFactory; | ||
|
||
@Test | ||
void displayEdit() | ||
{ | ||
XWikiContext xWikiContext = this.oldCore.getXWikiContext(); | ||
xWikiContext.setURLFactory(this.urlFactory); | ||
when(this.oldCore.getSpyXWiki().getURL("Main.WebHome", "view", xWikiContext)).thenReturn("/a/b"); | ||
|
||
String fieldName = "test"; | ||
String spaceName = "\" + alert(1) + \""; | ||
String pageName = "WebHome"; | ||
StringClass stringClass = new StringClass(); | ||
stringClass.setPicker(true); | ||
BaseClass baseClass = new BaseClass(); | ||
stringClass.setObject(baseClass); | ||
baseClass.setDocumentReference( | ||
new DocumentReference(this.oldCore.getXWikiContext().getWikiId(), spaceName, pageName)); | ||
stringClass.setName(fieldName); | ||
StringBuffer stringBuffer = new StringBuffer(); | ||
stringClass.displayEdit(stringBuffer, fieldName, spaceName + "." + pageName + "_0_", baseClass, | ||
xWikiContext); | ||
assertEquals("<input " | ||
+ "onfocus='new ajaxSuggest(this, {script:"\\/a\\/b?xpage=suggest&" | ||
+ "classname=%22%20%2B%20alert%281%29%20%2B%20%22.WebHome&fieldname=test&firCol=-&" | ||
+ "secCol=-&", varname:"input"} )' " | ||
+ "size='30' " | ||
+ "id='" + alert(1) + ".WebHome_0_test' " | ||
+ "class='suggested' " | ||
+ "name='" + alert(1) + ".WebHome_0_test' " | ||
+ "type='text'/>", stringBuffer.toString()); | ||
} | ||
} |