projects
/
pub
/
Android
/
ownCloud.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
515ec5e
)
OC-2115: Validate Path in RenameRemoteFileOperation
author
masensio
<masensio@solidgear.es>
Tue, 19 Nov 2013 08:07:11 +0000
(09:07 +0100)
committer
masensio
<masensio@solidgear.es>
Tue, 19 Nov 2013 08:07:11 +0000
(09:07 +0100)
oc_framework-test-project/oc_framework-test-test/src/com/owncloud/android/oc_framework_test_project/test/RenameFileTest.java
patch
|
blob
|
blame
|
history
oc_framework-test-project/src/com/owncloud/android/oc_framework_test_project/TestActivity.java
patch
|
blob
|
blame
|
history
oc_framework/src/com/owncloud/android/oc_framework/operations/remote/RenameRemoteFileOperation.java
patch
|
blob
|
blame
|
history
src/com/owncloud/android/operations/RenameFileOperation.java
patch
|
blob
|
blame
|
history
diff --git
a/oc_framework-test-project/oc_framework-test-test/src/com/owncloud/android/oc_framework_test_project/test/RenameFileTest.java
b/oc_framework-test-project/oc_framework-test-test/src/com/owncloud/android/oc_framework_test_project/test/RenameFileTest.java
index
f4c2cf6
..
fe30550
100644
(file)
--- a/
oc_framework-test-project/oc_framework-test-test/src/com/owncloud/android/oc_framework_test_project/test/RenameFileTest.java
+++ b/
oc_framework-test-project/oc_framework-test-test/src/com/owncloud/android/oc_framework_test_project/test/RenameFileTest.java
@@
-1,10
+1,7
@@
package com.owncloud.android.oc_framework_test_project.test;
package com.owncloud.android.oc_framework_test_project.test;
-import java.io.File;
-
import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
import com.owncloud.android.oc_framework.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
import com.owncloud.android.oc_framework.operations.RemoteOperationResult.ResultCode;
-import com.owncloud.android.oc_framework.utils.FileUtils;
import com.owncloud.android.oc_framework_test_project.TestActivity;
import android.test.ActivityInstrumentationTestCase2;
import com.owncloud.android.oc_framework_test_project.TestActivity;
import android.test.ActivityInstrumentationTestCase2;
@@
-13,16
+10,16
@@
public class RenameFileTest extends ActivityInstrumentationTestCase2<TestActivit
/* Folder data to rename. This folder must exist on the account */
private final String mOldFolderName = "folderToRename";
/* Folder data to rename. This folder must exist on the account */
private final String mOldFolderName = "folderToRename";
- private final String mOldFolderPath = "/folderToRename
/
";
+ private final String mOldFolderPath = "/folderToRename";
private final String mNewFolderName = "renamedFolder";
private final String mNewFolderName = "renamedFolder";
- private final String mNewFolderPath = "/renameFolder";
+ private final String mNewFolderPath = "/rename
d
Folder";
/* File data to rename. This file must exist on the account */
private final String mOldFileName = "fileToRename.png";
private final String mOldFilePath = "/fileToRename.png";
private final String mNewFileName = "renamedFile";
/* File data to rename. This file must exist on the account */
private final String mOldFileName = "fileToRename.png";
private final String mOldFilePath = "/fileToRename.png";
private final String mNewFileName = "renamedFile";
- private final String mNewFilePath = "/renamedFile";
private final String mFileExtension = ".png";
private final String mFileExtension = ".png";
+ private final String mNewFilePath ="/renamedFile.png";
private TestActivity mActivity;
private TestActivity mActivity;
@@
-45,49
+42,45
@@
public class RenameFileTest extends ActivityInstrumentationTestCase2<TestActivit
public void testRenameFolder() {
RemoteOperationResult result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
public void testRenameFolder() {
RemoteOperationResult result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
- mNewFolderName,
mNewFolderPath + FileUtils.PATH_SEPARATOR
);
+ mNewFolderName,
true
);
assertTrue(result.isSuccess());
}
/**
assertTrue(result.isSuccess());
}
/**
- * Test Rename Folder with forbidden characters :
/
\ < > : " | ? *
+ * Test Rename Folder with forbidden characters : \ < > : " | ? *
*/
public void testRenameFolderForbiddenChars() {
*/
public void testRenameFolderForbiddenChars() {
-
- RemoteOperationResult result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
- mNewFolderName + "//", mNewFolderPath + "//" + FileUtils.PATH_SEPARATOR);
- assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
- result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
- mNewFolderName + "\\",
mNewFolderPath + "\\" + FileUtils.PATH_SEPARATOR
);
+
RemoteOperationResult
result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
+ mNewFolderName + "\\",
true
);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
- mNewFolderName + "<",
mNewFolderPath + "<" + FileUtils.PATH_SEPARATOR
);
+ mNewFolderName + "<",
true
);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
- mNewFolderName + ">",
mNewFolderPath + ">" + FileUtils.PATH_SEPARATOR
);
+ mNewFolderName + ">",
true
);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
- mNewFolderName + ":",
mNewFolderPath + ":" + FileUtils.PATH_SEPARATOR
);
+ mNewFolderName + ":",
true
);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
- mNewFolderName + "\"",
mNewFolderPath + "\"" + FileUtils.PATH_SEPARATOR
);
+ mNewFolderName + "\"",
true
);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
- mNewFolderName + "|",
mNewFolderPath + "|" + FileUtils.PATH_SEPARATOR
);
+ mNewFolderName + "|",
true
);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
- mNewFolderName + "?",
mNewFolderPath + "?" + FileUtils.PATH_SEPARATOR
);
+ mNewFolderName + "?",
true
);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
- mNewFolderName + "*",
mNewFolderPath + "*" + FileUtils.PATH_SEPARATOR
);
+ mNewFolderName + "*",
true
);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
}
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
}
@@
-96,49
+89,45
@@
public class RenameFileTest extends ActivityInstrumentationTestCase2<TestActivit
*/
public void testRenameFile() {
RemoteOperationResult result = mActivity.renameFile(mOldFileName, mOldFilePath,
*/
public void testRenameFile() {
RemoteOperationResult result = mActivity.renameFile(mOldFileName, mOldFilePath,
- mNewFileName + mFileExtension,
mNewFilePath + mFileExtension
);
+ mNewFileName + mFileExtension,
false
);
assertTrue(result.isSuccess());
}
/**
assertTrue(result.isSuccess());
}
/**
- * Test Rename Folder with forbidden characters:
/
\ < > : " | ? *
+ * Test Rename Folder with forbidden characters: \ < > : " | ? *
*/
*/
- public void testRenameFileForbiddenChars() {
+ public void testRenameFileForbiddenChars() {
RemoteOperationResult result = mActivity.renameFile(mOldFileName, mOldFilePath,
RemoteOperationResult result = mActivity.renameFile(mOldFileName, mOldFilePath,
- mNewFileName + "//" + mFileExtension, mNewFilePath + "//" + mFileExtension);
- assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
-
- result = mActivity.renameFile(mOldFileName, mOldFilePath,
- mNewFileName + "\\" + mFileExtension, mNewFilePath + "\\" + mFileExtension);
+ mNewFileName + "\\" + mFileExtension, false);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFileName, mOldFilePath,
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFileName, mOldFilePath,
- mNewFileName + "<" + mFileExtension,
mNewFilePath + "<" + mFileExtension
);
+ mNewFileName + "<" + mFileExtension,
false
);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFileName, mOldFilePath,
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFileName, mOldFilePath,
- mNewFileName + ">" + mFileExtension,
mNewFilePath + ">" + mFileExtension
);
+ mNewFileName + ">" + mFileExtension,
false
);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFileName, mOldFilePath,
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFileName, mOldFilePath,
- mNewFileName + ":" + mFileExtension,
mNewFilePath + ":" + mFileExtension
);
+ mNewFileName + ":" + mFileExtension,
false
);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFileName, mOldFilePath,
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFileName, mOldFilePath,
- mNewFileName + "\"" + mFileExtension,
mNewFilePath + "\"" + mFileExtension
);
+ mNewFileName + "\"" + mFileExtension,
false
);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFileName, mOldFilePath,
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFileName, mOldFilePath,
- mNewFileName + "|" + mFileExtension,
mNewFilePath + "|" + mFileExtension
);
+ mNewFileName + "|" + mFileExtension,
false
);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFileName, mOldFilePath,
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFileName, mOldFilePath,
- mNewFileName + "?" + mFileExtension,
mNewFilePath + "?" + mFileExtension
);
+ mNewFileName + "?" + mFileExtension,
false
);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFileName, mOldFilePath,
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(mOldFileName, mOldFilePath,
- mNewFileName + "*" + mFileExtension,
mNewFilePath + "*" + mFileExtension
);
+ mNewFileName + "*" + mFileExtension,
false
);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
}
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
}
@@
-148,10
+137,10
@@
public class RenameFileTest extends ActivityInstrumentationTestCase2<TestActivit
* Restore initial conditions
*/
public void testRestoreInitialConditions() {
* Restore initial conditions
*/
public void testRestoreInitialConditions() {
- RemoteOperationResult result = mActivity.renameFile(mNewFolderName, mNewFolderPath, mOldFolderName,
mOldFolderPath
);
+ RemoteOperationResult result = mActivity.renameFile(mNewFolderName, mNewFolderPath, mOldFolderName,
true
);
assertTrue(result.isSuccess());
assertTrue(result.isSuccess());
- result = mActivity.renameFile(mNewFileName + mFileExtension, mNewFilePath
+ mFileExtension, mOldFileName, mOldFilePath
);
+ result = mActivity.renameFile(mNewFileName + mFileExtension, mNewFilePath
, mOldFileName, false
);
assertTrue(result.isSuccess());
}
assertTrue(result.isSuccess());
}
diff --git
a/oc_framework-test-project/src/com/owncloud/android/oc_framework_test_project/TestActivity.java
b/oc_framework-test-project/src/com/owncloud/android/oc_framework_test_project/TestActivity.java
index
dd194cf
..
7fdf9cd
100644
(file)
--- a/
oc_framework-test-project/src/com/owncloud/android/oc_framework_test_project/TestActivity.java
+++ b/
oc_framework-test-project/src/com/owncloud/android/oc_framework_test_project/TestActivity.java
@@
-87,14
+87,14
@@
public class TestActivity extends Activity {
* @param oldName Old name of the file.
* @param oldRemotePath Old remote path of the file. For folders it starts and ends by "/"
* @param newName New name to set as the name of file.
* @param oldName Old name of the file.
* @param oldRemotePath Old remote path of the file. For folders it starts and ends by "/"
* @param newName New name to set as the name of file.
- * @param
newRemotePath New remote path to move the file, for folders it starts and ends by "/"
+ * @param
isFolder 'true' for folder and 'false' for files
*
* @return
*/
*
* @return
*/
- public RemoteOperationResult renameFile(String oldName, String oldRemotePath, String newName,
String newRemotePath
) {
+ public RemoteOperationResult renameFile(String oldName, String oldRemotePath, String newName,
boolean isFolder
) {
- RenameRemoteFileOperation renameOperation = new RenameRemoteFileOperation(oldName, oldRemotePath, newName,
newRemotePath
);
+ RenameRemoteFileOperation renameOperation = new RenameRemoteFileOperation(oldName, oldRemotePath, newName,
isFolder
);
RemoteOperationResult result = renameOperation.execute(mClient);
return result;
RemoteOperationResult result = renameOperation.execute(mClient);
return result;
diff --git
a/oc_framework/src/com/owncloud/android/oc_framework/operations/remote/RenameRemoteFileOperation.java
b/oc_framework/src/com/owncloud/android/oc_framework/operations/remote/RenameRemoteFileOperation.java
index
2ead67b
..
ad6fffc
100644
(file)
--- a/
oc_framework/src/com/owncloud/android/oc_framework/operations/remote/RenameRemoteFileOperation.java
+++ b/
oc_framework/src/com/owncloud/android/oc_framework/operations/remote/RenameRemoteFileOperation.java
@@
-1,5
+1,7
@@
package com.owncloud.android.oc_framework.operations.remote;
package com.owncloud.android.oc_framework.operations.remote;
+import java.io.File;
+
import org.apache.jackrabbit.webdav.client.methods.DavMethodBase;
import android.util.Log;
import org.apache.jackrabbit.webdav.client.methods.DavMethodBase;
import android.util.Log;
@@
-35,15
+37,21
@@
public class RenameRemoteFileOperation extends RemoteOperation {
* Constructor
*
* @param oldName Old name of the file.
* Constructor
*
* @param oldName Old name of the file.
- * @param oldRemotePath Old remote path of the file.
For folders it starts and ends by "/"
+ * @param oldRemotePath Old remote path of the file.
* @param newName New name to set as the name of file.
* @param newName New name to set as the name of file.
- * @param
newRemotePath New remote path to move the file, for folders it starts and ends by "/"
+ * @param
isFolder 'true' for folder and 'false' for files
*/
*/
- public RenameRemoteFileOperation(String oldName, String oldRemotePath, String newName,
String newRemotePath
) {
+ public RenameRemoteFileOperation(String oldName, String oldRemotePath, String newName,
boolean isFolder
) {
mOldName = oldName;
mOldRemotePath = oldRemotePath;
mNewName = newName;
mOldName = oldName;
mOldRemotePath = oldRemotePath;
mNewName = newName;
- mNewRemotePath = newRemotePath;
+
+ String parent = (new File(mOldRemotePath)).getParent();
+ parent = (parent.endsWith(FileUtils.PATH_SEPARATOR)) ? parent : parent + FileUtils.PATH_SEPARATOR;
+ mNewRemotePath = parent + mNewName;
+ if (isFolder) {
+ mNewRemotePath += FileUtils.PATH_SEPARATOR;
+ }
}
/**
}
/**
@@
-66,6
+74,7
@@
public class RenameRemoteFileOperation extends RemoteOperation {
return new RemoteOperationResult(ResultCode.OK);
}
return new RemoteOperationResult(ResultCode.OK);
}
+
// check if a file with the new name already exists
if (client.existsFile(mNewRemotePath)) {
return new RemoteOperationResult(ResultCode.INVALID_OVERWRITE);
// check if a file with the new name already exists
if (client.existsFile(mNewRemotePath)) {
return new RemoteOperationResult(ResultCode.INVALID_OVERWRITE);
diff --git
a/src/com/owncloud/android/operations/RenameFileOperation.java
b/src/com/owncloud/android/operations/RenameFileOperation.java
index
a526f2f
..
ebeac79
100644
(file)
--- a/
src/com/owncloud/android/operations/RenameFileOperation.java
+++ b/
src/com/owncloud/android/operations/RenameFileOperation.java
@@
-98,8
+98,8
@@
public class RenameFileOperation extends RemoteOperation {
return new RemoteOperationResult(ResultCode.INVALID_OVERWRITE);
}
return new RemoteOperationResult(ResultCode.INVALID_OVERWRITE);
}
- RenameRemoteFileOperation operation = new RenameRemoteFileOperation(mFile.getFileName(), mFile.getRemotePath(),
mNewName,
- mNew
RemotePath
);
+ RenameRemoteFileOperation operation = new RenameRemoteFileOperation(mFile.getFileName(), mFile.getRemotePath(),
+ mNew
Name, mFile.isFolder()
);
result = operation.execute(client);
if (result.isSuccess()) {
result = operation.execute(client);
if (result.isSuccess()) {