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