Skip to content
Snippets Groups Projects
Commit 35e9073f authored by Simon Urli's avatar Simon Urli
Browse files

XWIKI-20339: Attachments name are not properly displayed with special characters

  * Ensure to properly escape translations
  * Provide a new integration test for it
parent a3fb3778
No related branches found
No related tags found
No related merge requests found
......@@ -30,12 +30,14 @@
import org.openqa.selenium.By;
import org.xwiki.flamingo.skin.test.po.AttachmentsPane;
import org.xwiki.flamingo.skin.test.po.AttachmentsViewPage;
import org.xwiki.model.reference.AttachmentReference;
import org.xwiki.model.reference.DocumentReference;
import org.xwiki.rest.model.jaxb.Page;
import org.xwiki.test.docker.junit5.TestConfiguration;
import org.xwiki.test.docker.junit5.TestReference;
import org.xwiki.test.docker.junit5.UITest;
import org.xwiki.test.ui.TestUtils;
import org.xwiki.test.ui.po.BasePage;
import org.xwiki.test.ui.po.ChangesPane;
import org.xwiki.test.ui.po.ComparePage;
import org.xwiki.test.ui.po.DeletePageOutcomePage;
......@@ -425,6 +427,25 @@ void addSeveralAttachmentsAtOnce(TestUtils setup, TestReference testReference, T
assertEquals(4, attachmentsPane.getNumberOfAttachments());
}
/**
* Check the display of delete attachment message when it contains special characters.
*/
@Test
@Order(8)
void deleteAttachmentWithSpecialChar(TestUtils setup, TestReference testReference)
{
setup.loginAsSuperAdmin();
setup.createPage(testReference, "Empty content");
String attachmentName = "<img src=x>";
AttachmentReference attachmentReference = new AttachmentReference(attachmentName, testReference);
setup.gotoPage(attachmentReference, "delattachment");
BasePage basePage = new BasePage();
assertEquals(String.format("Error\n"
+ "Failed to delete attachment %s\n"
+ "This attachment does not exist.", attachmentName),
basePage.getXWikiMessageContent());
}
private String getAttachmentsMacroContent(DocumentReference docRef)
{
StringBuilder sb = new StringBuilder();
......
......@@ -90,6 +90,7 @@
import org.xwiki.user.UserReference;
import org.xwiki.user.UserReferenceResolver;
import org.xwiki.velocity.VelocityManager;
import org.xwiki.xml.XMLUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xpn.xwiki.XWiki;
......@@ -234,7 +235,7 @@ protected ContextualAuthorizationManager getContextualAuthorizationManager()
protected String localizePlainOrKey(String key, Object... parameters)
{
return StringUtils.defaultString(getLocalization().getTranslationPlain(key, parameters), key);
return XMLUtils.escape(StringUtils.defaultString(getLocalization().getTranslationPlain(key, parameters), key));
}
protected JobProgressManager getProgress()
......
......@@ -1193,7 +1193,7 @@ private List<String> extractListFromReference(EntityReference reference)
for (EntityReference singleReference : spaceReference.removeParent(wikiReference).getReversedReferenceChain()) {
path.add(singleReference.getName());
}
if (reference.getType() == EntityType.DOCUMENT) {
if (reference.getType() == EntityType.DOCUMENT || reference.getType() == EntityType.ATTACHMENT) {
path.add(reference.getName());
}
return path;
......
......@@ -668,6 +668,18 @@ public boolean isForbidden()
return false;
}
/**
* @return the full text of an {@code xwikimessage} box displayed in the full content (e.g. in case of error).
* @since 15.1RC1
* @since 14.10.6
*/
public String getXWikiMessageContent()
{
return getDriver()
.findElementWithoutWaiting(By.xpath("//div[@id = 'mainContentArea']/div[contains(@class, 'xwikimessage')]"))
.getText();
}
/**
* Use the following keyboard shortcut and wait for a new page to load. This should be only used for shortcuts that
* indeed loads a new page.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment