Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ internal actual class File(dirPath:String?=null, name:String){
val newPath:CharArray = origPath.toCharArray()
val length = newPath.size
var newLength = 0
for (i in 0 until length) {
val initialIndex = if (origPath.startsWith("file://", true)) 7 else 0
for (i in initialIndex until length) {
val ch = newPath[i]
if (ch == '/') {
if (!lastWasSlash) {
Expand All @@ -93,15 +94,12 @@ internal actual class File(dirPath:String?=null, name:String){
if (lastWasSlash && newLength > 1) {
newLength--
}

// Reuse the original string if possible.
return if (newLength != length) {
val sb = StringBuilder(newLength)
sb.append(newPath)
sb.toString()
}
else {
origPath
}
return if (newLength != length) buildString(newLength) {
append(newPath)
setLength(newLength)
} else origPath
}

private fun join(prefix: String, suffix: String): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ internal actual class File(dirPath: String? = null, name: String) {
val newPath: CharArray = origPath.toCharArray()
val length = newPath.size
var newLength = 0
for (i in 0 until length) {
val initialIndex = if (origPath.startsWith("file://", true)) 7 else 0
for (i in initialIndex until length) {
val ch = newPath[i]
if (ch == '/') {
if (!lastWasSlash) {
Expand All @@ -110,12 +111,12 @@ internal actual class File(dirPath: String? = null, name: String) {
if (lastWasSlash && newLength > 1) {
newLength--
}

// Reuse the original string if possible.
return if (newLength != length) {
newPath.concatToString()
} else {
origPath
}
return if (newLength != length) buildString(newLength) {
append(newPath)
setLength(newLength)
} else origPath
}

private fun join(prefix: String, suffix: String): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ internal actual class File(dirPath:String? = null, name:String) {
val newPath:CharArray = origPath.toCharArray()
val length = newPath.size
var newLength = 0
for (ch in newPath) {
val initialIndex = if (origPath.startsWith("file://", true)) 7 else 0
for (i in initialIndex until length) {
val ch = newPath[i]
if (ch == separatorChar) {
if (!lastWasSlash) {
newPath[newLength++] = separatorChar
Expand All @@ -94,12 +96,12 @@ internal actual class File(dirPath:String? = null, name:String) {
if (lastWasSlash && newLength > 1) {
newLength--
}

// Reuse the original string if possible.
return if (newLength != length) {
newPath.concatToString()
} else {
origPath
}
return if (newLength != length) buildString(newLength) {
append(newPath)
setLength(newLength)
} else origPath
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@ class DatabaseConfigurationTest : BaseDatabaseTest(){
assertTrue(dbPathString.endsWith(TEST_DB_NAME))
}

@Test
fun databasePathRemovesExtraSlashes() {
val dbPathString = DatabaseFileContext.databasePath(TEST_DB_NAME, "//tmp//")
assertEquals("/tmp/$TEST_DB_NAME", dbPathString)
}

@Test
fun databasePathRemovesFileUrlPrefix() {
val dbPathString = DatabaseFileContext.databasePath(TEST_DB_NAME, "file:///tmp/")
assertEquals("/tmp/$TEST_DB_NAME", dbPathString)
}

@Test
fun databasePathRemovesFileUrlPrefixInCaps() {
val dbPathString = DatabaseFileContext.databasePath(TEST_DB_NAME, "FILE:///tmp/")
assertEquals("/tmp/$TEST_DB_NAME", dbPathString)
}

@Test
fun memoryOnlyTest(){
val conf = DatabaseConfiguration(
Expand Down