Skip to content
Permalink
Browse files Browse the repository at this point in the history
OO-5819: clean starting / for backward compatibility
  • Loading branch information
lainsr committed Nov 2, 2021
1 parent 53c1d96 commit 336d5ce
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main/java/org/olat/core/util/vfs/LocalFolderImpl.java
Expand Up @@ -373,6 +373,7 @@ public String toString() {

@Override
public VFSContainer createChildContainer(String name) {
name = cleanFilename(name); // backward compatibility
File fNewFile = new File(getBasefile(), name);
if(!isInPath(name)) {
log.warn("Could not create a new container::{} in container::{} - file out of parent directory", name, getBasefile().getAbsolutePath());
Expand All @@ -388,6 +389,7 @@ public VFSContainer createChildContainer(String name) {

@Override
public VFSLeaf createChildLeaf(String name) {
name = cleanFilename(name); // backward compatibility
File fNewFile = new File(getBasefile(), name);
try {
if(!isInPath(name)) {
Expand All @@ -407,6 +409,20 @@ public VFSLeaf createChildLeaf(String name) {
}
return new LocalFileImpl(fNewFile, this);
}

/**
* It was allowed to have a filename starting with /, but
* it's not legal.
*
* @param name The name
* @return Name without starting /
*/
private String cleanFilename(String name) {
if(name != null && name.startsWith("/")) {
name = name.substring(1, name.length());
}
return name;
}

@Override
public VFSItemFilter getDefaultItemFilter() {
Expand Down

0 comments on commit 336d5ce

Please sign in to comment.