Changed to use span

This commit is contained in:
BaronGreenback 2021-05-08 12:52:25 +01:00
parent 7185de970c
commit bd71de131c
4 changed files with 17 additions and 9 deletions

View File

@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MediaBrowser.Common.Extensions;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.Extensions.Primitives;
@ -61,19 +62,23 @@ namespace Jellyfin.Server.Middleware
}
var pairs = new Dictionary<string, StringValues>();
var queryString = unencodedKey.Split('&', System.StringSplitOptions.RemoveEmptyEntries);
var queryString = unencodedKey.SpanSplit('&');
foreach (var pair in queryString)
{
var item = pair.Split('=', System.StringSplitOptions.RemoveEmptyEntries);
if (item.Length > 0)
var item = pair.Split('=');
item.MoveNext();
var key = item.Current;
var val = item.MoveNext() ? item.Current : string.Empty;
if (key.Length == 0 && val.Length == 0)
{
pairs.Add(item[0], new StringValues(item.Length == 2 ? item[1] : string.Empty));
}
else
{
pairs.Add(pair, string.Empty);
// encoded is an equals.
pairs.Add(pair.ToString(), new StringValues(string.Empty));
continue;
}
pairs.Add(key.ToString(), new StringValues(val.ToString()));
}
_store = new QueryCollection(pairs);

View File

@ -37,6 +37,7 @@
<ItemGroup>
<ProjectReference Include="../../Jellyfin.Api/Jellyfin.Api.csproj" />
<ProjectReference Include="../../Jellyfin.Server.Implementations/Jellyfin.Server.Implementations.csproj" />
<ProjectReference Include="..\Jellyfin.Server.Integration.Tests\Jellyfin.Server.Integration.Tests.csproj" />
</ItemGroup>
</Project>

View File

@ -42,6 +42,7 @@
<ItemGroup>
<ProjectReference Include="..\..\Emby.Server.Implementations\Emby.Server.Implementations.csproj" />
<ProjectReference Include="..\..\Jellyfin.Server.Implementations\Jellyfin.Server.Implementations.csproj" />
<ProjectReference Include="..\Jellyfin.Server.Integration.Tests\Jellyfin.Server.Integration.Tests.csproj" />
</ItemGroup>
</Project>

View File

@ -5,9 +5,10 @@ using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Jellyfin.Server.Integration.Tests;
using Xunit;
namespace Jellyfin.Api.Tests.Controllers
namespace Jellyfin.Server.Implementations.Tests.Middleware
{
/// <summary>
/// Defines the test for encoded querystrings in the url.