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

OO-4871: validate filename against + character in single page

parent 9da70963
No related branches found
No related tags found
No related merge requests found
......@@ -98,7 +98,8 @@ public class FileLinkChooserController extends BasicController {
* index.html
*/
public FileLinkChooserController(UserRequest ureq, WindowControl wControl,
VFSContainer rootDir, String uploadRelPath, String absolutePath, String[] suffixes, boolean uriValidation, String fileName) {
VFSContainer rootDir, String uploadRelPath, String absolutePath, String[] suffixes,
boolean uriValidation, boolean htmlLinkValidation, String fileName) {
super(ureq, wControl);
this.fileName = fileName;
this.suffixes = suffixes;
......@@ -173,6 +174,7 @@ 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, String fileName,
String uploadRelPath, String absolutPath, String[] suffixes, boolean uriValidation, boolean htmlExtraValidation, String fileName,
CustomLinkTreeModel customLinkTreeModel, CustomLinkTreeModel toolLinkTreeModel, boolean allowCustomMediaChooserFactory) {
super(ureq, wControl);
......@@ -82,7 +82,8 @@ public class LinkChooserController extends BasicController {
linkChooserTabbedPane = new TabbedPane("linkChooserTabbedPane", ureq.getLocale());
tabbedPaneViewVC.put("linkChooserTabbedPane", linkChooserTabbedPane);
fileLinkChooserController = new FileLinkChooserController(ureq, wControl, rootDir, uploadRelPath, absolutPath, suffixes, uriValidation, fileName);
fileLinkChooserController = new FileLinkChooserController(ureq, wControl, rootDir, uploadRelPath, absolutPath, suffixes,
uriValidation, htmlExtraValidation, fileName);
listenTo(fileLinkChooserController);
linkChooserTabbedPane.addTab(translate("linkchooser.tabbedpane.label.filechooser"), fileLinkChooserController.getInitialComponent());
......
......@@ -64,13 +64,9 @@ 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, false, fileName, customLinkTreeModel, null, allowCustomMediaFactory);
super(ureq, wControl, rootDir, uploadRelPath, null, suffixes, true, false, fileName, customLinkTreeModel, null, allowCustomMediaFactory);
}
/**
* @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
* org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
*/
@Override
public void event(UserRequest ureq, Controller source, Event event) {
fireEvent(ureq, event);
......
......@@ -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, "", null, null, true);
super(ureq, wControl, rootDir, null, null, null, false, false, "", null, null, true);
this.folderComponent = folderComponent;
}
......
......@@ -35,6 +35,7 @@ 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;
......@@ -108,7 +109,14 @@ 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;
......@@ -129,6 +137,7 @@ public class FileUploadController extends FormBasicController {
private long remainingQuotKB;
private Set<String> mimeTypes;
private boolean uriValidation;
private boolean htmlLinkValidation;
//
// Form elements
private FileElement fileEl;
......@@ -836,6 +845,14 @@ 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;
}
......@@ -954,6 +971,15 @@ 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, uriValidation, fileName, linkBrowserCustomTreeModel, toolLinkTreeModel, allowCustomMediaFactory);
myLinkChooserController = new LinkChooserController(lureq, lwControl, baseContainer, uploadRelPath, absolutePath, suffixes, true, 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, uriValidation, fileName, null, null, allowCustomMediaFactory);
myLinkChooserController = new LinkChooserController(lureq, lwControl, baseContainer, uploadRelPath, absolutePath, suffixes, true, 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, "", null, null, true);
super(ureq, wControl, rootDir, uploadRelPath, null, null, false, 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