Skip to content
Snippets Groups Projects
Commit eab01742 authored by srosse's avatar srosse
Browse files

OO-4871: escape + in file name for single pages

parent a64f8863
No related branches found
No related tags found
No related merge requests found
......@@ -99,7 +99,7 @@ public class FileLinkChooserController extends BasicController {
*/
public FileLinkChooserController(UserRequest ureq, WindowControl wControl,
VFSContainer rootDir, String uploadRelPath, String absolutePath, String[] suffixes,
boolean uriValidation, boolean htmlLinkValidation, String fileName) {
boolean uriValidation, String fileName) {
super(ureq, wControl);
this.fileName = fileName;
this.suffixes = suffixes;
......@@ -174,7 +174,6 @@ public class FileLinkChooserController extends BasicController {
uploadCtr = new FileUploadController(wControl, fileUploadBase, ureq, uploadLimit, remainingSpace,
mimeTypes, uriValidation, true, false, true, true, false);
uploadCtr.setHtmlLinkValidation(htmlLinkValidation);
listenTo(uploadCtr);
// set specific upload path
uploadCtr.setUploadRelPath(uploadRelPath);
......
......@@ -73,7 +73,7 @@ public class LinkChooserController extends BasicController {
* internalLinkTreeModel is null.
*/
public LinkChooserController(UserRequest ureq, WindowControl wControl, VFSContainer rootDir,
String uploadRelPath, String absolutPath, String[] suffixes, boolean uriValidation, boolean htmlExtraValidation, String fileName,
String uploadRelPath, String absolutPath, String[] suffixes, boolean uriValidation, String fileName,
CustomLinkTreeModel customLinkTreeModel, CustomLinkTreeModel toolLinkTreeModel, boolean allowCustomMediaChooserFactory) {
super(ureq, wControl);
......@@ -83,7 +83,7 @@ public class LinkChooserController extends BasicController {
tabbedPaneViewVC.put("linkChooserTabbedPane", linkChooserTabbedPane);
fileLinkChooserController = new FileLinkChooserController(ureq, wControl, rootDir, uploadRelPath, absolutPath, suffixes,
uriValidation, htmlExtraValidation, fileName);
uriValidation, fileName);
listenTo(fileLinkChooserController);
linkChooserTabbedPane.addTab(translate("linkchooser.tabbedpane.label.filechooser"), fileLinkChooserController.getInitialComponent());
......@@ -119,35 +119,59 @@ public class LinkChooserController extends BasicController {
@Override
public void event(UserRequest ureq, Controller source, Event event) {
if (event instanceof URLChoosenEvent) {
// send choosen URL to parent window via JavaScript and close the window
URLChoosenEvent urlChoosenEvent = (URLChoosenEvent) event;
closeVC = createVelocityContainer("close");
String url = urlChoosenEvent.getURL();
closeVC.contextPut("isJsUrl", Boolean.FALSE);
if (url.contains("gotonode") || url.contains("gototool")) {
closeVC.contextPut("isJsUrl", Boolean.TRUE);
}
closeVC.contextPut("imagepath", url);
if(urlChoosenEvent.getWidth() > 0) {
closeVC.contextPut("width", Integer.toString(urlChoosenEvent.getWidth()));
}
if(urlChoosenEvent.getHeight() > 0) {
closeVC.contextPut("height", Integer.toString(urlChoosenEvent.getHeight()));
}
mainPanel.setContent(closeVC);
URLChoosenEvent urlChoosenEvent = (URLChoosenEvent)event;
doSendUrlToTiny(urlChoosenEvent);
} else if (event == Event.CANCELLED_EVENT) {
removeAsListenerAndDispose(fileLinkChooserController);
removeAsListenerAndDispose(courseLinkChooserController);
removeAsListenerAndDispose(courseToolLinkChooserController);
removeAsListenerAndDispose(customMediaChooserCtr);
// Close the window, no URL selected
closeVC = createVelocityContainer("close");
closeVC.contextPut("imagepath", "");
mainPanel.setContent(closeVC);
doCancel();
}
}
private void doSendUrlToTiny(URLChoosenEvent urlChoosenEvent) {
cleanUp();
// send choosen URL to parent window via JavaScript and close the window
closeVC = createVelocityContainer("close");
String url = urlChoosenEvent.getURL();
closeVC.contextPut("isJsUrl", Boolean.FALSE);
String escapedUrl;
if (url.contains("gotonode") || url.contains("gototool")) {
escapedUrl = url;
closeVC.contextPut("isJsUrl", Boolean.TRUE);
} else if(url.startsWith("http://") || url.startsWith("https://")) {
escapedUrl = url;
} else {
escapedUrl = escapeUrl(url);
}
closeVC.contextPut("imagepath", escapedUrl);
if(urlChoosenEvent.getWidth() > 0) {
closeVC.contextPut("width", Integer.toString(urlChoosenEvent.getWidth()));
}
if(urlChoosenEvent.getHeight() > 0) {
closeVC.contextPut("height", Integer.toString(urlChoosenEvent.getHeight()));
}
mainPanel.setContent(closeVC);
}
private String escapeUrl(String url) {
return url.replace("+", "%2b");
}
private void doCancel() {
cleanUp();
// Close the window, no URL selected
closeVC = createVelocityContainer("close");
closeVC.contextPut("imagepath", "");
mainPanel.setContent(closeVC);
}
private void cleanUp() {
removeAsListenerAndDispose(fileLinkChooserController);
removeAsListenerAndDispose(courseLinkChooserController);
removeAsListenerAndDispose(courseToolLinkChooserController);
removeAsListenerAndDispose(customMediaChooserCtr);
}
@Override
protected void doDispose() {
......
......@@ -64,7 +64,7 @@ public class MediaChooserController extends LinkChooserController {
*/
public MediaChooserController(UserRequest ureq, WindowControl wControl, VFSContainer rootDir, String uploadRelPath, String[] suffixes, String fileName,
CustomLinkTreeModel customLinkTreeModel, boolean allowCustomMediaFactory) {
super(ureq, wControl, rootDir, uploadRelPath, null, suffixes, true, false, fileName, customLinkTreeModel, null, allowCustomMediaFactory);
super(ureq, wControl, rootDir, uploadRelPath, null, suffixes, false, fileName, customLinkTreeModel, null, allowCustomMediaFactory);
}
@Override
......
......@@ -91,7 +91,7 @@ public class FileCopyController extends LinkChooserController {
public FileCopyController(UserRequest ureq, WindowControl wControl, VFSContainer rootDir,
FolderComponent folderComponent) {
super(ureq, wControl, rootDir, null, null, null, false, false, "", null, null, true);
super(ureq, wControl, rootDir, null, null, null, false, "", null, null, true);
this.folderComponent = folderComponent;
}
......
......@@ -35,7 +35,6 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
......@@ -109,13 +108,6 @@ import org.springframework.beans.factory.annotation.Autowired;
* @author Florian Gnägi
*/
public class FileUploadController extends FormBasicController {
/**
* Extra validation for the htmlLinkValidation option
*/
private static final char[] HTML_EXTRA_FORBIDDEN_CHARS = { '+' };
static {
Arrays.sort(HTML_EXTRA_FORBIDDEN_CHARS);
}
private static final String[] resizeKeys = new String[]{"resize"};
private int status = FolderCommandStatus.STATUS_SUCCESS;
......@@ -137,7 +129,6 @@ public class FileUploadController extends FormBasicController {
private long remainingQuotKB;
private Set<String> mimeTypes;
private boolean uriValidation;
private boolean htmlLinkValidation;
//
// Form elements
private FileElement fileEl;
......@@ -845,14 +836,6 @@ public class FileUploadController extends FormBasicController {
}
}
public boolean isHtmlLinkValidation() {
return htmlLinkValidation;
}
public void setHtmlLinkValidation(boolean htmlLinkValidation) {
this.htmlLinkValidation = htmlLinkValidation;
}
public String getNewFileName() {
return (this.newFile != null) ? this.newFile.getName() : null;
}
......@@ -971,15 +954,6 @@ public class FileUploadController extends FormBasicController {
itemEl.setErrorKey("cfile.name.notvalid.uri", null);
allOk &= false;
}
} else if(htmlLinkValidation) {
for(int i=0; i<filename.length(); i++) {
char character = filename.charAt(i);
if(Arrays.binarySearch(HTML_EXTRA_FORBIDDEN_CHARS, character) >= 0) {
itemEl.setErrorKey("cfile.name.notvalid", null);
allOk &= false;
break;
}
}
}
return allOk;
......
......@@ -181,10 +181,10 @@ class RichTextElementComponent extends FormBaseComponentImpl {
CustomLinkTreeModel toolLinkTreeModel = config.getToolLinkTreeModel();
if (type.equals(CMD_FILEBROWSER)) {
// when in file mode we include the internal links to the selection
myLinkChooserController = new LinkChooserController(lureq, lwControl, baseContainer, uploadRelPath, absolutePath, suffixes, true, uriValidation, fileName, linkBrowserCustomTreeModel, toolLinkTreeModel, allowCustomMediaFactory);
myLinkChooserController = new LinkChooserController(lureq, lwControl, baseContainer, uploadRelPath, absolutePath, suffixes, uriValidation, fileName, linkBrowserCustomTreeModel, toolLinkTreeModel, allowCustomMediaFactory);
} else {
// in media or image mode, internal links make no sense here
myLinkChooserController = new LinkChooserController(lureq, lwControl, baseContainer, uploadRelPath, absolutePath, suffixes, true, uriValidation, fileName, null, null, allowCustomMediaFactory);
myLinkChooserController = new LinkChooserController(lureq, lwControl, baseContainer, uploadRelPath, absolutePath, suffixes, uriValidation, fileName, null, null, allowCustomMediaFactory);
}
return new LayoutMain3ColsController(lureq, lwControl, myLinkChooserController);
}
......
......@@ -346,7 +346,7 @@ public class DialogCourseNodeRunController extends BasicController implements Ac
private class MyLinkChooserController extends LinkChooserController {
public MyLinkChooserController(UserRequest ureq, WindowControl wControl, VFSContainer rootDir, String uploadRelPath) {
super(ureq, wControl, rootDir, uploadRelPath, null, null, false, false, "", null, null, true);
super(ureq, wControl, rootDir, uploadRelPath, null, null, false, "", null, null, true);
}
@Override
......
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