mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-06 06:21:16 +07:00
svn: Fix "Url.toString()" for "file:///" urls
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user