diff --git a/src/se/vidstige/jadb/Transport.java b/src/se/vidstige/jadb/Transport.java index 6ce363d..72a828c 100644 --- a/src/se/vidstige/jadb/Transport.java +++ b/src/se/vidstige/jadb/Transport.java @@ -51,7 +51,7 @@ class Transport implements Closeable { } private String getCommandLength(String command) { - return String.format("%04x", command.length()); + return String.format("%04x", command.getBytes().length); } public void send(String command) throws IOException { diff --git a/src/se/vidstige/jadb/managers/Bash.java b/src/se/vidstige/jadb/managers/Bash.java index 34fddbb..e8b3368 100644 --- a/src/se/vidstige/jadb/managers/Bash.java +++ b/src/se/vidstige/jadb/managers/Bash.java @@ -6,10 +6,6 @@ public class Bash { } public static String quote(String s) { - // Check that s contains no whitespace - if (s.matches("\\S+")) { - return s; - } return "'" + s.replace("'", "'\\''") + "'"; } } diff --git a/test/se/vidstige/jadb/test/integration/ExecuteCmdTests.java b/test/se/vidstige/jadb/test/integration/ExecuteCmdTests.java new file mode 100644 index 0000000..7443e4f --- /dev/null +++ b/test/se/vidstige/jadb/test/integration/ExecuteCmdTests.java @@ -0,0 +1,66 @@ +package se.vidstige.jadb.test.integration; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import se.vidstige.jadb.JadbConnection; +import se.vidstige.jadb.JadbDevice; +import se.vidstige.jadb.Stream; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.Collection; + +@RunWith(Parameterized.class) +public class ExecuteCmdTests { + private static JadbConnection jadb; + private static JadbDevice jadbDevice; + + @Parameterized.Parameter + public String input; + + + @Parameterized.Parameters(name="Test {index} input={0}") + public static Collection input() { + return Arrays.asList(new Object[]{ + "öäasd", + "asf dsa", + "sdf&g", + "sd& fg", + "da~f", + "asd'as", + "a¡f", + "asüd", + "adös tz", + "⾀", + "å", + "æ", + "{}"}); + } + + @BeforeClass + public static void connect() { + try { + jadb = new JadbConnection(); + jadb.getHostVersion(); + jadbDevice = jadb.getAnyDevice(); + } catch (Exception e) { + org.junit.Assume.assumeNoException(e); + } + } + + + @Test + public void testExecuteWithSpecialChars() throws Exception { + InputStream response = jadbDevice.execute("echo", input); + Assert.assertEquals(input, Stream.readAll(response, StandardCharsets.UTF_8).replaceAll("\n$", "")); + } +} diff --git a/test/se/vidstige/jadb/test/unit/MockedTestCases.java b/test/se/vidstige/jadb/test/unit/MockedTestCases.java index 87ec980..017acef 100644 --- a/test/se/vidstige/jadb/test/unit/MockedTestCases.java +++ b/test/se/vidstige/jadb/test/unit/MockedTestCases.java @@ -119,11 +119,15 @@ public class MockedTestCases { server.expectShell("serial-123", "echo 'tab\tstring'").returns("tab\tstring"); server.expectShell("serial-123", "echo 'newline1\nstring'").returns("newline1\nstring"); server.expectShell("serial-123", "echo 'newline2\r\nstring'").returns("newline2\r\nstring"); + server.expectShell("serial-123", "echo 'fuö äzpo'").returns("fuö äzpo"); + server.expectShell("serial-123", "echo 'h¡t]&poli'").returns("h¡t]&poli"); JadbDevice device = connection.getDevices().get(0); device.executeShell("ls", "space file"); device.executeShell("echo", "tab\tstring"); device.executeShell("echo", "newline1\nstring"); device.executeShell("echo", "newline2\r\nstring"); + device.executeShell("echo", "fuö äzpo"); + device.executeShell("echo", "h¡t]&poli"); } @Test