mirror of
https://github.com/revanced/jadb.git
synced 2024-11-19 10:39:23 +01:00
Merge pull request #70 from muhikhsan101/quote-whitespaced-args
Quote Command Arguments with Whitespace
This commit is contained in:
commit
551d475851
@ -3,9 +3,9 @@
|
||||
<extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" />
|
||||
<module name="jadb" />
|
||||
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
|
||||
<option name="ALTERNATIVE_JRE_PATH" value="" />
|
||||
<option name="PACKAGE_NAME" value="se.vidstige.jadb.test" />
|
||||
<option name="MAIN_CLASS_NAME" value="se.vidstige.jadb.test.MockedTestCases" />
|
||||
<option name="ALTERNATIVE_JRE_PATH" />
|
||||
<option name="PACKAGE_NAME" value="se.vidstige.jadb.test.unit" />
|
||||
<option name="MAIN_CLASS_NAME" value="se.vidstige.jadb.test.unit.MockedTestCases" />
|
||||
<option name="METHOD_NAME" value="" />
|
||||
<option name="TEST_OBJECT" value="class" />
|
||||
<option name="VM_PARAMETERS" value="-ea" />
|
||||
|
@ -2,8 +2,8 @@ package se.vidstige.jadb.managers;
|
||||
|
||||
public class Bash {
|
||||
public static String quote(String s) {
|
||||
// TODO: Should also check other whitespace
|
||||
if (!s.contains(" ")) {
|
||||
// Check that s contains no whitespace
|
||||
if (s.matches("\\S+")) {
|
||||
return s;
|
||||
}
|
||||
return "'" + s.replace("'", "'\\''") + "'";
|
||||
|
@ -152,6 +152,7 @@ public class FakeAdbServer implements AdbResponder {
|
||||
|
||||
public void verifyExpectations() {
|
||||
org.junit.Assert.assertEquals(0, fileExpectations.size());
|
||||
org.junit.Assert.assertEquals(0, shellExpectations.size());
|
||||
}
|
||||
|
||||
private class FileExpectation implements ExpectationBuilder {
|
||||
|
@ -104,11 +104,17 @@ public class MockedTestCases {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteShellQuotesSpace() throws Exception {
|
||||
public void testExecuteShellQuotesWhitespace() throws Exception {
|
||||
server.add("serial-123");
|
||||
server.expectShell("serial-123", "ls 'space file'").returns("space file");
|
||||
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");
|
||||
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");
|
||||
}
|
||||
|
||||
private long parseDate(String date) throws ParseException {
|
||||
|
Loading…
Reference in New Issue
Block a user