Skip to content

Commit

Permalink
VFS-844: Prevent that source files urlString is twice (#423)
Browse files Browse the repository at this point in the history
URIEncoded.

Prevent that the urlString of a webdav-filename is twice URIEncoded when file is moved. Results in invalid filename if the filename contains spaces.

Co-authored-by: Thorsten Beise <[email protected]>
  • Loading branch information
beise and Thorsten Beise authored Sep 16, 2023
1 parent 223d569 commit 5f3a26c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.apache.commons.vfs2.provider.http4.Http4FileObject;
import org.apache.commons.vfs2.util.FileObjectUtils;
import org.apache.commons.vfs2.util.MonitorOutputStream;
import org.apache.commons.vfs2.util.URIUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
Expand Down Expand Up @@ -423,7 +422,7 @@ protected FileObject[] doListChildrenResolved() throws Exception {
*/
@Override
protected void doRename(final FileObject newFile) throws Exception {
final String url = URIUtils.encodePath(toUrlString((GenericURLFileName) getName()));
final String url = toUrlString((GenericURLFileName) getName());
final String dest = toUrlString((GenericURLFileName) newFile.getName(), false);
final HttpMove request = new HttpMove(url, dest, false);
setupRequest(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,23 @@ public void testRenameFile() throws Exception {
moveFile(scratchFolder, file, content);
}

/**
* Tests create-delete-create-a-file sequence on the same file system.
*/
@Test
public void testRenameFileWithSpaces() throws Exception {
final FileObject scratchFolder = createScratchFolder();

// Create direct child of the test folder
final FileObject file = scratchFolder.resolveFile("file space.txt");
assertFalse(file.exists());

final String content = createTestFile(file);

// Make sure we can move the new file to another file on the same file system
moveFile(scratchFolder, file, content);
}

/**
* Moves a file from a child folder to a parent folder to test what happens when the original folder is now empty.
*
Expand Down

0 comments on commit 5f3a26c

Please sign in to comment.