mirror of
https://github.com/TeamAmaze/AmazeFileManager.git
synced 2026-10-17 05:08:00 +08:00
@@ -25,6 +25,8 @@ import com.amaze.filemanager.filesystem.ftp.NetCopyClientConnectionPool.FTP_URI_
|
||||
import com.amaze.filemanager.filesystem.ftp.NetCopyClientConnectionPool.SSH_URI_PREFIX
|
||||
import com.amaze.filemanager.filesystem.ftp.NetCopyConnectionInfo.Companion.COLON
|
||||
import com.amaze.filemanager.filesystem.smb.CifsContexts.SMB_URI_PREFIX
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
/**
|
||||
* Container object for SSH/FTP/FTPS URL, encapsulating logic for splitting information from given
|
||||
@@ -58,6 +60,9 @@ class NetCopyConnectionInfo(url: String) {
|
||||
private set
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
private val LOGGER: Logger = LoggerFactory.getLogger(NetCopyConnectionInfo::class.java)
|
||||
|
||||
// Regex taken from https://blog.stevenlevithan.com/archives/parseuri
|
||||
// (No, don't break it down to lines)
|
||||
|
||||
@@ -104,7 +109,12 @@ class NetCopyConnectionInfo(url: String) {
|
||||
* Invalid string would have been trapped to other branches. Strings fell into
|
||||
* this branch must be integer
|
||||
*/
|
||||
it[7].toInt()
|
||||
try {
|
||||
it[7].toInt()
|
||||
} catch (e: NumberFormatException) {
|
||||
LOGGER.warn("Unable to parse port number: ${it[7]}", e)
|
||||
0
|
||||
}
|
||||
} else {
|
||||
0
|
||||
}
|
||||
|
||||
@@ -334,4 +334,26 @@ class NetCopyConnectionInfoTest {
|
||||
assertEquals("test.log", this.lastPathSegment())
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test parsing invalid port number.
|
||||
*/
|
||||
@Test
|
||||
fun testParseInvalidPortNumber() {
|
||||
NetCopyConnectionInfo("ssh://user:pass@127.0.0.1:22/a/b/c/d/e").run {
|
||||
assertEquals(22, this.port)
|
||||
}
|
||||
NetCopyConnectionInfo("ssh://user:pass@127.0.0.1:21097/a/b/c/d/e").run {
|
||||
assertEquals(21097, this.port)
|
||||
}
|
||||
NetCopyConnectionInfo("ssh://user:pass@127.0.0.1/a/b/c/d/e").run {
|
||||
assertEquals(0, this.port)
|
||||
}
|
||||
NetCopyConnectionInfo("ssh://user:pass@127.0.0.1:2109775003564/a/b/c/d/e").run {
|
||||
assertEquals(0, this.port)
|
||||
}
|
||||
NetCopyConnectionInfo("ssh://user:pass@127.0.0.1:${Long.MAX_VALUE}/a/b/c/d/e").run {
|
||||
assertEquals(0, this.port)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user