mirror of
https://github.com/CalcProgrammer1/OpenRGB.git
synced 2026-09-20 17:28:11 -04:00
Update MacOS and Linux AutoStart implementations to properly escape special characters in paths
This commit is contained in:
1 parent
41b7087e20
commit
ecf0bfc847
2 files changed
+107
-4
No files matched your search
@@ -137,6 +137,43 @@ std::string AutoStart::GetExePath()
|
||||
| Private Methods |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Escape a string for embedding inside an XML element |
|
||||
| (used by the .plist generator) to avoid producing |
|
||||
| malformed property list files. |
|
||||
\*---------------------------------------------------------*/
|
||||
static std::string XmlEscape(const std::string& input)
|
||||
{
|
||||
std::string escaped;
|
||||
|
||||
for(char c : input)
|
||||
{
|
||||
switch(c)
|
||||
{
|
||||
case '&':
|
||||
escaped += "&";
|
||||
break;
|
||||
case '<':
|
||||
escaped += "<";
|
||||
break;
|
||||
case '>':
|
||||
escaped += ">";
|
||||
break;
|
||||
case '"':
|
||||
escaped += """;
|
||||
break;
|
||||
case '\'':
|
||||
escaped += "'";
|
||||
break;
|
||||
default:
|
||||
escaped += c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return(escaped);
|
||||
}
|
||||
|
||||
std::string AutoStart::GenerateLaunchAgentFile(AutoStartInfo autostart_info)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
@@ -153,7 +190,8 @@ std::string AutoStart::GenerateLaunchAgentFile(AutoStartInfo autostart_info)
|
||||
fileContents << " <string>org.openrgb</string>" << std::endl;
|
||||
fileContents << " <key>ProgramArguments</key>" << std::endl;
|
||||
fileContents << " <array>" << std::endl;
|
||||
fileContents << " <string>" << autostart_info.path << "</string>" << std::endl;
|
||||
fileContents << " <string>" << XmlEscape(autostart_info.path) << "</string>"
|
||||
<< std::endl;
|
||||
|
||||
if(autostart_info.args != "")
|
||||
{
|
||||
@@ -162,7 +200,8 @@ std::string AutoStart::GenerateLaunchAgentFile(AutoStartInfo autostart_info)
|
||||
|
||||
while(arg_parser >> arg)
|
||||
{
|
||||
fileContents << " <string>" << arg << "</string>" << std::endl;
|
||||
fileContents << " <string>" << XmlEscape(arg) << "</string>"
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user