Merge "Fix search for values in blkId output"
This commit is contained in:
commit
0fbc5af676
2 changed files with 12 additions and 5 deletions
13
Utils.cpp
13
Utils.cpp
|
@ -202,12 +202,15 @@ status_t BindMount(const std::string& source, const std::string& target) {
|
|||
|
||||
bool FindValue(const std::string& raw, const std::string& key, std::string* value) {
|
||||
auto qual = key + "=\"";
|
||||
auto start = raw.find(qual);
|
||||
if (start > 0 && raw[start - 1] != ' ') {
|
||||
start = raw.find(qual, start + 1);
|
||||
size_t start = 0;
|
||||
while (true) {
|
||||
start = raw.find(qual, start);
|
||||
if (start == std::string::npos) return false;
|
||||
if (start == 0 || raw[start - 1] == ' ') {
|
||||
break;
|
||||
}
|
||||
start += 1;
|
||||
}
|
||||
|
||||
if (start == std::string::npos) return false;
|
||||
start += qual.length();
|
||||
|
||||
auto end = raw.find("\"", start);
|
||||
|
|
|
@ -27,6 +27,7 @@ TEST_F(UtilsTest, FindValueTest) {
|
|||
std::string tmp;
|
||||
|
||||
ASSERT_FALSE(FindValue("", "KEY", &tmp));
|
||||
ASSERT_FALSE(FindValue("NOTMATCH=\"VALUE\"", "KEY", &tmp));
|
||||
ASSERT_FALSE(FindValue("BADKEY=\"VALUE\"", "KEY", &tmp));
|
||||
|
||||
ASSERT_TRUE(FindValue("KEY=\"VALUE\"", "KEY", &tmp));
|
||||
|
@ -37,6 +38,9 @@ TEST_F(UtilsTest, FindValueTest) {
|
|||
|
||||
ASSERT_TRUE(FindValue("BADKEY=\"VALUE\" KEY=\"BAZ\"", "KEY", &tmp));
|
||||
ASSERT_EQ("BAZ", tmp);
|
||||
|
||||
ASSERT_TRUE(FindValue("BADKEY=\"VALUE\" NOTKEY=\"OTHER\" KEY=\"QUUX\"", "KEY", &tmp));
|
||||
ASSERT_EQ("QUUX", tmp);
|
||||
}
|
||||
|
||||
} // namespace vold
|
||||
|
|
Loading…
Reference in a new issue