Skip to content

Commit

Permalink
Fix crash caused by incorrect VNC URIs
Browse files Browse the repository at this point in the history
If user passed 'vnc:something' instead of 'vnc://something', it would
lead to a crash because 'vnc:something' is not a valid VNC URI.
  • Loading branch information
gujjwal00 committed May 17, 2023
1 parent 505abaa commit 385e7b8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/src/androidTest/java/com/gaurav/avnc/vnc/VncUriTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,10 @@ class VncUriTest {
val uri = VncUri("[fe80:2a10:b62b]")
assertEquals("", uri.host)
}

@Test
fun opaqueUri() {
// Correct format is 'vnc://host'
assertEquals("", VncUri("vnc:host").host)
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/gaurav/avnc/vnc/VncUri.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class VncUri(private val uri: Uri) {
*
* It also serves as a validation step because [URI] verifies that address is well-formed.
*/
private val javaUri = runCatching { URI(uri.toString()) }.getOrDefault(URI(""))
private val javaUri = runCatching { URI(uri.toString()).also { check(!it.isOpaque) } }.getOrDefault(URI(""))


val host = javaUri.host?.trim('[', ']') ?: ""
Expand Down

0 comments on commit 385e7b8

Please sign in to comment.