Allow having semi-colons in quoted arguments in the cmd part of mimeview defs

This commit is contained in:
Jean-Francois Dockes
2022-04-05 08:48:12 +02:00
parent 4ebffd1a31
commit 7ef02a3b09
3 changed files with 162 additions and 109 deletions
+10 -4
View File
@@ -905,11 +905,17 @@ bool RclConfig::getGuiFilter(const string& catfiltername, string& frag) const
return true;
}
bool RclConfig::valueSplitAttributes(const string& whole, string& value,
ConfSimple& attrs)
bool RclConfig::valueSplitAttributes(const string& whole, string& value, ConfSimple& attrs)
{
/* There is currently no way to escape a semi-colon */
string::size_type semicol0 = whole.find_first_of(";");
bool inquote{false};
string::size_type semicol0;
for (semicol0 = 0; semicol0 < whole.size(); semicol0++) {
if (whole[semicol0] == '"') {
inquote = !inquote;
} else if (whole[semicol0] == ';' && !inquote) {
break;
}
}
value = whole.substr(0, semicol0);
trimstring(value);
string attrstr;
+10 -4
View File
@@ -259,12 +259,18 @@ public:
string getMimeHandlerDef(const string &mimetype, bool filtertypes=false,
const std::string& fn = std::string());
/** For lines like: "name = some value; attr1 = value1; attr2 = val2"
/** For lines like: [name = some value; attr1 = value1; attr2 = val2]
* Separate the value and store the attributes in a ConfSimple
* @param whole the raw value. No way to escape a semi-colon in there.
*
* In the value part, semi-colons inside double quotes are ignored, and double quotes are
* conserved. In the common case where the string is then processed by stringToStrings() to
* build a command line, this allows having semi-colons inside arguments. However, no backslash
* escaping is possible, so that, for example "bla\"1;2\"" would not work (the value part
* would stop at the semi-colon).
*
* @param whole the raw value.
*/
static bool valueSplitAttributes(const string& whole, string& value,
ConfSimple& attrs) ;
static bool valueSplitAttributes(const string& whole, string& value, ConfSimple& attrs) ;
/** Compute difference between 'base' and 'changed', as elements to be
* added and substracted from base. Input and output strings are in