String arg;
BOOST_FOREACH(arg, args) {
// This is obviously incorrect for non-trivial cases.
- fp << " \"" << arg << "\"";
+ fp << " \"" << EscapeString(arg) << "\"";
}
} else if (!commandLine.IsEmpty()) {
- fp << Convert::ToString(commandLine);
+ fp << EscapeString(Convert::ToString(commandLine));
} else {
fp << "<internal>";
}
<< "\n";
}
+String CompatComponent::EscapeString(const String& str)
+{
+ String result = str;
+ boost::algorithm::replace_all(result, "\n", "\\n");
+ return result;
+}
+
void CompatComponent::DumpServiceStatusAttrs(std::ostream& fp, const Service::Ptr& service, CompatObjectType type)
{
ASSERT(service->OwnsLock());
if (line_end > 0 && line_end != String::NPos) {
long_output = raw_output.SubStr(line_end+1, raw_output.GetLength());
- boost::algorithm::replace_all(long_output, "\n", "\\n");
+ long_output = EscapeString(long_output);
}
boost::algorithm::replace_all(output, "\n", "\\n");