Skip to content

Commit aa2de85

Browse files
Merge branch 'dev' into robertwoj/38214321
2 parents da011ad + f90706d commit aa2de85

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

  • src/modules/complianceengine/src/assessor

src/modules/complianceengine/src/assessor/Mof.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,32 @@ string GetValue(const std::string& line)
2020
{
2121
return std::string();
2222
}
23-
const auto end = line.find('"', start + 1);
24-
if (end == std::string::npos)
23+
// Walk from the opening quote, honouring \" and \\ escape sequences so
24+
// that MOF string values like "{\"key\":\"val\"}" are returned
25+
// unescaped as {"key":"val"} instead of being truncated at the first
26+
// inner quote.
27+
std::string result;
28+
size_t pos = start + 1;
29+
while (pos < line.size())
2530
{
26-
return std::string();
31+
if (line[pos] == '\\' && pos + 1 < line.size())
32+
{
33+
const char next = line[pos + 1];
34+
if (next == '"' || next == '\\')
35+
{
36+
result += next;
37+
pos += 2;
38+
continue;
39+
}
40+
}
41+
else if (line[pos] == '"')
42+
{
43+
break;
44+
}
45+
result += line[pos];
46+
++pos;
2747
}
28-
return line.substr(start + 1, end - (start + 1));
48+
return result;
2949
};
3050
} // anonymous namespace
3151

0 commit comments

Comments
 (0)