Skip to content

Commit 1130900

Browse files
authored
Merge pull request #28 from flatcar/tormath1/kv-store
kv-store: support quoted values
2 parents a95d6d8 + db448f9 commit 1130900

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/update_engine/simple_key_value_store.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@ map<std::string, std::string> ParseString(const string& str) {
2727
string::size_type pos = it->find('=');
2828
if (pos == string::npos)
2929
continue;
30-
ret[it->substr(0, pos)] = it->substr(pos + 1);
30+
string val = it->substr(pos + 1);
31+
if ((val.length() >= 2) &&
32+
((val.front() == '\"' && val.back() == '\"') ||
33+
(val.front() == '\'' && val.back() == '\''))) {
34+
val = val.substr(1, val.length() - 2);
35+
}
36+
37+
ret[it->substr(0, pos)] = val;
3138
}
3239
return ret;
3340
}

src/update_engine/simple_key_value_store_unittest.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,25 @@ namespace chromeos_update_engine {
1818
class SimpleKeyValueStoreTest : public ::testing::Test {};
1919

2020
TEST(SimpleKeyValueStoreTest, SimpleTest) {
21-
string blob = "A=B\nC=\n=\nFOO=BAR=BAZ\nBAR=BAX\nMISSING=NEWLINE";
21+
string blob = "A=B\nC=\n=\nFOO=BAR=BAZ\nALIAS='my alias'\nEMPTY=''\nD=\"\"\nTEST=\"this is a test\"\nBAR=BAX\nMISSING=NEWLINE";
2222
map<string, string> parts = simple_key_value_store::ParseString(blob);
2323
string combined = simple_key_value_store::AssembleString(parts);
2424
map<string, string> combined_parts =
2525
simple_key_value_store::ParseString(combined);
2626
map<string, string>* maps[] = { &parts, &combined_parts };
2727
for (size_t i = 0; i < arraysize(maps); i++) {
2828
map<string, string>* test_map = maps[i];
29-
EXPECT_EQ(6, test_map->size()) << "i = " << i;
29+
EXPECT_EQ(10, test_map->size()) << "i = " << i;
3030
EXPECT_EQ("B", (*test_map)["A"]) << "i = " << i;
3131
EXPECT_EQ("", (*test_map)["C"]) << "i = " << i;
3232
EXPECT_EQ("", (*test_map)[""]) << "i = " << i;
3333
EXPECT_EQ("BAR=BAZ", (*test_map)["FOO"]) << "i = " << i;
3434
EXPECT_EQ("BAX", (*test_map)["BAR"]) << "i = " << i;
3535
EXPECT_EQ("NEWLINE", (*test_map)["MISSING"]) << "i = " << i;
36+
EXPECT_EQ("my alias", (*test_map)["ALIAS"]) << "i = " << i;
37+
EXPECT_EQ("this is a test", (*test_map)["TEST"]) << "i = " << i;
38+
EXPECT_EQ("", (*test_map)["EMPTY"]) << "i = " << i;
39+
EXPECT_EQ("", (*test_map)["D"]) << "i = " << i;
3640
}
3741
}
3842

0 commit comments

Comments
 (0)