mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-08 04:20:13 +02:00
Move XML escaping to a separate function
This commit is contained in:
+4
-27
@@ -407,37 +407,14 @@ bool send_notification(const std::string& title, const std::string body) {
|
||||
// I think there's a zero chance that we're going to call this function with
|
||||
// anything that even somewhat resembles HTML, but we should still do a
|
||||
// basic XML escape anyways.
|
||||
// Implementation idea stolen from https://stackoverflow.com/a/5665377
|
||||
std::string escaped_body{};
|
||||
escaped_body.reserve(
|
||||
static_cast<size_t>(static_cast<double>(body.size()) * 1.1));
|
||||
for (const char& character : body) {
|
||||
switch (character) {
|
||||
case '&':
|
||||
escaped_body.append("&");
|
||||
break;
|
||||
case '\"':
|
||||
escaped_body.append(""");
|
||||
break;
|
||||
case '\'':
|
||||
escaped_body.append("'");
|
||||
break;
|
||||
case '<':
|
||||
escaped_body.append("<");
|
||||
break;
|
||||
case '>':
|
||||
escaped_body.append(">");
|
||||
break;
|
||||
default:
|
||||
escaped_body.push_back(character);
|
||||
break;
|
||||
}
|
||||
}
|
||||
std::ostringstream formatted_body;
|
||||
formatted_body << xml_escape(body);
|
||||
|
||||
try {
|
||||
return bp::system(notify_send_path, "--urgency=normal",
|
||||
"--expire-time=30000", "--app-name=yabridge", title,
|
||||
escaped_body, bp::posix::use_vfork) == EXIT_SUCCESS;
|
||||
formatted_body.str(),
|
||||
bp::posix::use_vfork) == EXIT_SUCCESS;
|
||||
} catch (const boost::process::process_error&) {
|
||||
// We will have printed the message to the terminal anyways, so if the
|
||||
// user doesn't have libnotify installed we'll just fail silently
|
||||
|
||||
Reference in New Issue
Block a user