diff options
author | Mohamed Zenadi <mohamed@zenadi.com> | 2017-08-02 00:48:45 +0100 |
---|---|---|
committer | Mohamed Zenadi <zeapo@users.noreply.github.com> | 2017-08-10 11:10:29 +0200 |
commit | 09480d939013e0ebe9d8d89d57ae461d63c181d4 (patch) | |
tree | 452572b4a32e0c70ecbd1c9e5c0c25d5cbd464a7 /app/src | |
parent | f80d13a5b32684e12020ece4a1cc9aa2ad0f4f98 (diff) |
Ensure that we have a single `/`
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/androidTest/java/com/zeapo/pwdstore/DecryptTest.kt | 19 | ||||
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt | 4 |
2 files changed, 15 insertions, 8 deletions
diff --git a/app/src/androidTest/java/com/zeapo/pwdstore/DecryptTest.kt b/app/src/androidTest/java/com/zeapo/pwdstore/DecryptTest.kt index 2bf1083e..6823f67a 100644 --- a/app/src/androidTest/java/com/zeapo/pwdstore/DecryptTest.kt +++ b/app/src/androidTest/java/com/zeapo/pwdstore/DecryptTest.kt @@ -56,12 +56,19 @@ class DecryptTest { @Test fun pathShouldDecompose() { - init() - - assertEquals("/category/sub.gpg", PgpActivity.getRelativePath(path, repoPath)) - assertEquals("/category/", PgpActivity.getParentPath(path, repoPath)) - assertEquals("sub", PgpActivity.getName(path, repoPath)) - assertEquals("sub", PgpActivity.getName(path, "$repoPath/")) + val pathOne = "/fake/path/cat1/n1.gpg".replace("//", "/") + val pathTwo = "/fake/path/n2.gpg".replace("//", "/") + + assertEquals("/cat1/n1.gpg", PgpActivity.getRelativePath(pathOne, "/fake/path")) + assertEquals("/cat1/", PgpActivity.getParentPath(pathOne, "/fake/path")) + assertEquals("n1", PgpActivity.getName(pathOne, "/fake/path")) + // 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 diff --git a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt index 6bfac55f..73c9f935 100644 --- a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt +++ b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt @@ -570,7 +570,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { * Gets the relative path to the repository */ fun getRelativePath(fullPath: String, repositoryPath: String): String = - fullPath.replace(repositoryPath, "").replace("//", "/") + fullPath.replace(repositoryPath, "").replace("/+".toRegex(), "/") /** * Gets the Parent path, relative to the repository @@ -578,7 +578,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { fun getParentPath(fullPath: String, repositoryPath: String) : String { val relativePath = getRelativePath(fullPath, repositoryPath) val index = relativePath.lastIndexOf("/") - return "/${relativePath.substring(startIndex = 0, endIndex = index + 1)}/".replace("//", "/") + return "/${relativePath.substring(startIndex = 0, endIndex = index + 1)}/".replace("/+".toRegex(), "/") } /** |