From 30ee8be82e44d1a8250d1f6e27e71f7d5f24aec5 Mon Sep 17 00:00:00 2001 From: Lena Date: Wed, 1 Jul 2026 00:00:00 +0000 Subject: app: enter the device address as one host:port field The form asked for a host, a pairing port and a connection port as three separate fields. Nothing on screen says which port is which, and the two are only distinguishable if the reader already knows how adb pair works on Android 11+. Take the connection endpoint the way the target prints it, as a single "ip:port" string copied off the Wireless debugging screen, and leave the pairing dialog with just its port and code. Devices.parseAddress() does the split and rejects anything malformed rather than guessing: an unbracketed IPv6 literal would otherwise be split at the wrong colon. Reported on the F-Droid submission (fdroiddata!41394). --- .../test/java/invalid/lena/scrcpy/DevicesTest.java | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'app/src/test/java/invalid/lena') diff --git a/app/src/test/java/invalid/lena/scrcpy/DevicesTest.java b/app/src/test/java/invalid/lena/scrcpy/DevicesTest.java index d1e4f02..dcd04ca 100644 --- a/app/src/test/java/invalid/lena/scrcpy/DevicesTest.java +++ b/app/src/test/java/invalid/lena/scrcpy/DevicesTest.java @@ -1,6 +1,7 @@ package invalid.lena.scrcpy; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import org.junit.Test; @@ -52,6 +53,47 @@ public class DevicesTest { assertEquals(43210, out.get(1).port); } + @Test + public void parseAddressSplitsHostAndPort() { + Devices.Device d = Devices.parseAddress(" 192.168.1.42:41234 "); + assertEquals("192.168.1.42", d.host); + assertEquals(41234, d.port); + + Devices.Device v6 = Devices.parseAddress("[fe80::1]:5555"); + assertEquals("fe80::1", v6.host); + assertEquals(5555, v6.port); + // Round-trips through the display form. + assertEquals("[fe80::1]:5555", v6.toString()); + } + + @Test + public void parseAddressRejectsMalformed() { + // No port, empty host, non-numeric and out-of-range ports. + assertNull(Devices.parseAddress(null)); + assertNull(Devices.parseAddress("")); + assertNull(Devices.parseAddress("192.168.1.42")); + assertNull(Devices.parseAddress(":5555")); + assertNull(Devices.parseAddress("192.168.1.42:")); + assertNull(Devices.parseAddress("192.168.1.42:port")); + assertNull(Devices.parseAddress("192.168.1.42:0")); + assertNull(Devices.parseAddress("192.168.1.42:65536")); + // Unbracketed IPv6 would otherwise split at the wrong colon. + assertNull(Devices.parseAddress("fe80::1:5555")); + assertNull(Devices.parseAddress("[fe80::1]5555")); + } + + @Test + public void parsePortRejectsNonDigits() { + assertEquals(5555, Devices.parsePort(" 5555 ")); + assertEquals(1, Devices.parsePort("1")); + assertEquals(65535, Devices.parsePort("65535")); + assertEquals(-1, Devices.parsePort("")); + assertEquals(-1, Devices.parsePort("+5555")); + assertEquals(-1, Devices.parsePort("-1")); + assertEquals(-1, Devices.parsePort("55x5")); + assertEquals(-1, Devices.parsePort("655360")); + } + @Test public void deviceEqualsByHostAndPort() { Devices.Device a = new Devices.Device("1.1.1.1", 5555); -- cgit v1.2.3