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

Merge pull request #5 from Difegue/dev

1.3.0
This commit is contained in:
Difegue 2022-01-21 17:41:08 +01:00 committed by GitHub
commit 28e5dbd334
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 6 deletions

View File

@ -174,12 +174,10 @@ namespace MpcNET.Commands.Database
/// </returns>
public string Serialize()
{
var cmd =
CommandName + " \"(" +
string.Join(" AND ",
var serializedFilters = string.Join(" AND ",
filters.Select(x => $"({x.Key.Value} {Operand} {escape(x.Value)})")
) +
")\"";
);
var cmd = $@"{CommandName} ""({serializedFilters})""";
if (_start > -1)
{
@ -201,7 +199,30 @@ namespace MpcNET.Commands.Database
return MpdFile.CreateList(response.ResponseValues);
}
private string escape(string value) => string.Format("\\\"{0}\\\"", value.Replace("\\", "\\\\\\").Replace("'", "\\\\'").Replace("\"", "\\\\\\\""));
/// <summary>
/// String values are quoted with single or double quotes,
/// 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,
/// which means you may need to use double backslash.
///
/// Example expression which matches an artist named foo'bar":
/// (Artist == "foo\'bar\"")
///
/// At the protocol level, the command must look like this:
/// find "(Artist == \"foo\\'bar\\\"\")"
///
/// (https://mpd.readthedocs.io/en/stable/protocol.html#filter-syntax)
/// </summary>
/// <param name="value">Value to escape</param>
/// <returns></returns>
private string escape(string value)
{
var escapedValue = value.Replace(@"\", @"\\\\")
.Replace("'", @"\\'")
.Replace(@"""", @"\\\""");
return $@"\""{escapedValue}\""";
}
}
// TODO: rescan
}

View File

@ -24,6 +24,8 @@
<PackageTags>mpd;client;mpcNET</PackageTags>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">