Use ' quoting to escape arguments.
The specific motivating case is "text;ls;1.apk", but rather than continue
adding individual characters to the list of characters to be escaped, let's
just switch to quote all arguments with ', which only leaves ' itself to be
escaped.
Bug: 20323053
Bug: 19734868
Change-Id: I8bd71db9373bc2d1169fc11e46c889da6638550a
diff --git a/adb_utils_test.cpp b/adb_utils_test.cpp
index 95e28a8..a395079 100644
--- a/adb_utils_test.cpp
+++ b/adb_utils_test.cpp
@@ -25,28 +25,28 @@
}
TEST(adb_utils, escape_arg) {
- ASSERT_EQ(R"("")", escape_arg(""));
+ ASSERT_EQ(R"('')", escape_arg(""));
- ASSERT_EQ(R"(abc)", escape_arg("abc"));
+ ASSERT_EQ(R"('abc')", escape_arg("abc"));
- ASSERT_EQ(R"(\ abc)", escape_arg(" abc"));
- ASSERT_EQ(R"(\'abc)", escape_arg("'abc"));
- ASSERT_EQ(R"(\"abc)", escape_arg("\"abc"));
- ASSERT_EQ(R"(\\abc)", escape_arg("\\abc"));
- ASSERT_EQ(R"(\(abc)", escape_arg("(abc"));
- ASSERT_EQ(R"(\)abc)", escape_arg(")abc"));
+ ASSERT_EQ(R"(' abc')", escape_arg(" abc"));
+ ASSERT_EQ(R"('\'abc')", escape_arg("'abc"));
+ ASSERT_EQ(R"('"abc')", escape_arg("\"abc"));
+ ASSERT_EQ(R"('\abc')", escape_arg("\\abc"));
+ ASSERT_EQ(R"('(abc')", escape_arg("(abc"));
+ ASSERT_EQ(R"(')abc')", escape_arg(")abc"));
- ASSERT_EQ(R"(abc\ abc)", escape_arg("abc abc"));
- ASSERT_EQ(R"(abc\'abc)", escape_arg("abc'abc"));
- ASSERT_EQ(R"(abc\"abc)", escape_arg("abc\"abc"));
- ASSERT_EQ(R"(abc\\abc)", escape_arg("abc\\abc"));
- ASSERT_EQ(R"(abc\(abc)", escape_arg("abc(abc"));
- ASSERT_EQ(R"(abc\)abc)", escape_arg("abc)abc"));
+ ASSERT_EQ(R"('abc abc')", escape_arg("abc abc"));
+ ASSERT_EQ(R"('abc\'abc')", escape_arg("abc'abc"));
+ ASSERT_EQ(R"('abc"abc')", escape_arg("abc\"abc"));
+ ASSERT_EQ(R"('abc\abc')", escape_arg("abc\\abc"));
+ ASSERT_EQ(R"('abc(abc')", escape_arg("abc(abc"));
+ ASSERT_EQ(R"('abc)abc')", escape_arg("abc)abc"));
- ASSERT_EQ(R"(abc\ )", escape_arg("abc "));
- ASSERT_EQ(R"(abc\')", escape_arg("abc'"));
- ASSERT_EQ(R"(abc\")", escape_arg("abc\""));
- ASSERT_EQ(R"(abc\\)", escape_arg("abc\\"));
- ASSERT_EQ(R"(abc\()", escape_arg("abc("));
- ASSERT_EQ(R"(abc\))", escape_arg("abc)"));
+ ASSERT_EQ(R"('abc ')", escape_arg("abc "));
+ ASSERT_EQ(R"('abc\'')", escape_arg("abc'"));
+ ASSERT_EQ(R"('abc"')", escape_arg("abc\""));
+ ASSERT_EQ(R"('abc\')", escape_arg("abc\\"));
+ ASSERT_EQ(R"('abc(')", escape_arg("abc("));
+ ASSERT_EQ(R"('abc)')", escape_arg("abc)"));
}