Skip to content

Commit

Permalink
Merge pull request #996 from nextcloud/fix/double-slash
Browse files Browse the repository at this point in the history
NextcloudUriDelegate: avoid double-slash in files dav paths
  • Loading branch information
AlvaroBrey committed Nov 15, 2022
2 parents a7e8143 + 471c23a commit e39a3c4
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.nextcloud.common

import android.net.Uri
import org.junit.Assert
import org.junit.Before
import org.junit.Test

class NextcloudUriDelegateIT {

lateinit var sut: NextcloudUriDelegate

@Before
fun setUp() {
sut = NextcloudUriDelegate(Uri.parse(BASEURL), USERID)
}

@Test
fun testFilesDavUri_leadingSlashInPath() {
val expected = "$EXPECTED_FILES_DAV/path/to/file.txt"
val actual = sut.getFilesDavUri("/path/to/file.txt")
Assert.assertEquals("Wrong URL", expected, actual)
}

@Test
fun testFilesDavUri_noLeadingSlashInPath() {
val expected = "$EXPECTED_FILES_DAV/path/to/file.txt"
val actual = sut.getFilesDavUri("path/to/file.txt")
Assert.assertEquals("Wrong URL", expected, actual)
}

@Test
fun testFilesDavUri_emptyPath() {
val expected = "$EXPECTED_FILES_DAV/"
val actual = sut.getFilesDavUri("")
Assert.assertEquals("Wrong URL", expected, actual)
}

@Test
fun testFilesDavUri_rootPath() {
val expected = "$EXPECTED_FILES_DAV/"
val actual = sut.getFilesDavUri("/")
Assert.assertEquals("Wrong URL", expected, actual)
}

companion object {
private const val USERID = "user"
private const val BASEURL = "http://test.localhost"
private const val EXPECTED_FILES_DAV = "$BASEURL/remote.php/dav/files/$USERID"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class NextcloudUriDelegate(baseUri: Uri, var userId: String?) : NextcloudUriProv
get() = Uri.parse(baseUri.toString() + AccountUtils.WEBDAV_PATH_9_0)

override fun getFilesDavUri(path: String): String {
return "$filesDavUri/${WebdavUtils.encodePath(path)}"
// encodePath already adds leading slash if needed
return "$filesDavUri${WebdavUtils.encodePath(path)}"
}

override fun getCommentsUri(fileId: String): String {
Expand Down

0 comments on commit e39a3c4

Please sign in to comment.