1
0
mirror of https://github.com/ZetaKebab/MpcNET.git synced 2024-09-16 05:30:09 +00:00

Filters: restore correct escape value

This commit is contained in:
Théo Marchal 2022-03-28 13:07:03 +02:00
parent 316cfb0a31
commit d907f9b6e3

View File

@ -100,8 +100,6 @@ namespace MpcNET.Types
} }
/// <summary> /// <summary>
/// Gets the formatted command
///
/// String values are quoted with single or double quotes, /// String values are quoted with single or double quotes,
/// and special characters within those values must be escaped with the backslash (\). /// and special characters within those values must be escaped with the backslash (\).
/// Keep in mind that the backslash is also the escape character on the protocol level, /// Keep in mind that the backslash is also the escape character on the protocol level,
@ -115,21 +113,28 @@ namespace MpcNET.Types
/// ///
/// (https://mpd.readthedocs.io/en/stable/protocol.html#filters) /// (https://mpd.readthedocs.io/en/stable/protocol.html#filters)
/// </summary> /// </summary>
/// <param name="value">Value to escape</param>
/// <returns></returns>
private string escape(string value)
{
var escapedValue = value.Replace(@"\", @"\\\\")
.Replace("'", @"\\'")
.Replace(@"""", @"\\\""");
return $@"\""{escapedValue}\""";
}
/// <summary>
/// Gets the formatted command
/// </summary>
public string GetFormattedCommand() public string GetFormattedCommand()
{ {
string make = ""; string command = $"({Name} {Operator.GetDescription()} {escape(Value)})";
if (Negation) if (Negation)
make += "(!"; return $"(!{command})";
else
make += "(" + Name + " "; return command;
make += Operator.GetDescription();
make += " " + "\\\"" + Value + "\\\"" + ")";
if (Negation)
make += ")";
return make;
} }
} }
} }