mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-06-03 06:18:28 +01:00
Merge pull request #5990 from BaronGreenback/UrlDecoding
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Jellyfin.Api.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Controller for testing the encoded url.
|
||||
/// </summary>
|
||||
public class EncoderController : BaseJellyfinApiController
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests the url decoding.
|
||||
/// </summary>
|
||||
/// <param name="params">Parameters to echo back in the response.</param>
|
||||
/// <returns>An <see cref="OkResult"/>.</returns>
|
||||
/// <response code="200">Information retrieved.</response>
|
||||
[HttpGet("UrlDecode")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
public ContentResult TestUrlDecoding([FromQuery] Dictionary<string, string>? @params = null)
|
||||
{
|
||||
return new ContentResult()
|
||||
{
|
||||
Content = (@params != null && @params.Count > 0)
|
||||
? string.Join("&", @params.Select(x => x.Key + "=" + x.Value))
|
||||
: string.Empty,
|
||||
ContentType = "text/plain; charset=utf-8",
|
||||
StatusCode = 200
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace Jellyfin.Server.Integration.Tests
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the test for encoded querystrings in the url.
|
||||
/// </summary>
|
||||
public class EncodedQueryStringTest : IClassFixture<JellyfinApplicationFactory>
|
||||
{
|
||||
private readonly JellyfinApplicationFactory _factory;
|
||||
|
||||
public EncodedQueryStringTest(JellyfinApplicationFactory factory)
|
||||
{
|
||||
_factory = factory;
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("a=1&b=2&c=3", "a=1&b=2&c=3")] // won't be processed as there is more than 1.
|
||||
[InlineData("a=1", "a=1")] // won't be processed as it has a value
|
||||
[InlineData("a%3D1%26b%3D2%26c%3D3", "a=1&b=2&c=3")] // will be processed.
|
||||
public async Task Ensure_Decoding_Of_Urls_Is_Working(string sourceUrl, string unencodedUrl)
|
||||
{
|
||||
var client = _factory.CreateClient();
|
||||
|
||||
var response = await client.GetAsync("Encoder/UrlDecode?" + sourceUrl).ConfigureAwait(false);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
string reply = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||
Assert.Equal(unencodedUrl, reply);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user