mirror of
https://github.com/android-password-store/Android-Password-Store
synced 2025-09-01 14:55:19 +00:00
Ensure that we have a single /
This commit is contained in:
committed by
Mohamed Zenadi
parent
f80d13a5b3
commit
09480d9390
@@ -56,12 +56,19 @@ class DecryptTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun pathShouldDecompose() {
|
fun pathShouldDecompose() {
|
||||||
init()
|
val pathOne = "/fake/path/cat1/n1.gpg".replace("//", "/")
|
||||||
|
val pathTwo = "/fake/path/n2.gpg".replace("//", "/")
|
||||||
|
|
||||||
assertEquals("/category/sub.gpg", PgpActivity.getRelativePath(path, repoPath))
|
assertEquals("/cat1/n1.gpg", PgpActivity.getRelativePath(pathOne, "/fake/path"))
|
||||||
assertEquals("/category/", PgpActivity.getParentPath(path, repoPath))
|
assertEquals("/cat1/", PgpActivity.getParentPath(pathOne, "/fake/path"))
|
||||||
assertEquals("sub", PgpActivity.getName(path, repoPath))
|
assertEquals("n1", PgpActivity.getName(pathOne, "/fake/path"))
|
||||||
assertEquals("sub", PgpActivity.getName(path, "$repoPath/"))
|
// test that even if we append a `/` it still works
|
||||||
|
assertEquals("n1", PgpActivity.getName(pathOne, "/fake/path/"))
|
||||||
|
|
||||||
|
assertEquals("/n2.gpg", PgpActivity.getRelativePath(pathTwo, "/fake/path"))
|
||||||
|
assertEquals("/", PgpActivity.getParentPath(pathTwo, "/fake/path"))
|
||||||
|
assertEquals("n2", PgpActivity.getName(pathTwo, "/fake/path"))
|
||||||
|
assertEquals("n2", PgpActivity.getName(pathTwo, "/fake/path/"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -570,7 +570,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
|
|||||||
* Gets the relative path to the repository
|
* Gets the relative path to the repository
|
||||||
*/
|
*/
|
||||||
fun getRelativePath(fullPath: String, repositoryPath: String): String =
|
fun getRelativePath(fullPath: String, repositoryPath: String): String =
|
||||||
fullPath.replace(repositoryPath, "").replace("//", "/")
|
fullPath.replace(repositoryPath, "").replace("/+".toRegex(), "/")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the Parent path, relative to the repository
|
* Gets the Parent path, relative to the repository
|
||||||
@@ -578,7 +578,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
|
|||||||
fun getParentPath(fullPath: String, repositoryPath: String) : String {
|
fun getParentPath(fullPath: String, repositoryPath: String) : String {
|
||||||
val relativePath = getRelativePath(fullPath, repositoryPath)
|
val relativePath = getRelativePath(fullPath, repositoryPath)
|
||||||
val index = relativePath.lastIndexOf("/")
|
val index = relativePath.lastIndexOf("/")
|
||||||
return "/${relativePath.substring(startIndex = 0, endIndex = index + 1)}/".replace("//", "/")
|
return "/${relativePath.substring(startIndex = 0, endIndex = index + 1)}/".replace("/+".toRegex(), "/")
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user