svn: Fix "Url.toString()" for "file:///" urls

This commit is contained in:
Konstantin Kolosovsky
2018-03-31 19:21:00 +03:00
parent ac47585ada
commit 1b7db1834d
2 changed files with 19 additions and 1 deletions
@@ -8,6 +8,8 @@ import org.jetbrains.idea.svn.commandLine.SvnBindException
import java.net.URI
import java.net.URISyntaxException
private const val FILE_URL_PREFIX = "file:/"
class Url private constructor(innerUri: URI) {
private val uri = fixDefaultPort(innerUri)
@@ -47,9 +49,13 @@ class Url private constructor(innerUri: URI) {
override fun hashCode() = uri.hashCode()
override fun toString() = uri.toASCIIString().removeSuffix("/")
override fun toString() = fixFileUrlToString(uri.toASCIIString().removeSuffix("/"))
fun toDecodedString() = URLUtil.unescapePercentSequences(toString())
private fun fixFileUrlToString(url: String) = if (url.startsWith(FILE_URL_PREFIX) && !url.startsWith(
"$FILE_URL_PREFIX/")) "$FILE_URL_PREFIX//${url.substring(FILE_URL_PREFIX.length)}"
else url
companion object {
@JvmField
val EMPTY = Url(URI(""))
@@ -33,6 +33,18 @@ class UrlTest {
assertEquals("http://aaa/b b", Url.parse("http://aaa/b%20b").toDecodedString())
}
@Test
fun `file protocol to string`() {
assertEquals("file://localhost/home", Url.parse("file://localhost/home").toString())
assertEquals("file://localhost/home/aaa", Url.parse("file://localhost/home").appendPath("aaa").toString())
assertEquals("file:///home", Url.parse("file:///home").toString())
assertEquals("file:///home/aaa", Url.parse("file:///home").appendPath("aaa").toString())
assertEquals("file:///C:/svn", Url.parse("file:///C:/svn").toString())
assertEquals("file:///C:/svn/aaa", Url.parse("file:///C:/svn").appendPath("aaa").toString())
}
@Test
fun `append path`() {
val url = Url.parse("http://aaa")