The Free Software Media System - Server Backend & API
tests and small fix.
BaronGreenback4f5c9e95041a
diff --git a/Jellyfin.Api/Controllers/SystemController.cs b/Jellyfin.Api/Controllers/SystemController.csindex bbbe5fb8da..5c64d731b6 100644--- a/Jellyfin.Api/Controllers/SystemController.cs+++ b/Jellyfin.Api/Controllers/SystemController.cs@@ -84,13 +84,19 @@ namespace Jellyfin.Api.Controllers/// <summary>/// Pings the system./// </summary>+ /// <param name="params">Optional: Parameters to echo back in the response.</param>/// <response code="200">Information retrieved.</response>/// <returns>The server name.</returns>[HttpGet("Ping", Name = "GetPingSystem")][HttpPost("Ping", Name = "PostPingSystem")][ProducesResponseType(StatusCodes.Status200OK)]- public ActionResult<string> PingSystem()+ public ActionResult<string> PingSystem([FromQuery]Dictionary<string, string>? @params = null){+ if (@params != null && @params.Count > 0)+ {+ Response.Headers.Add("querystring", string.Join("&", @params.Select(x => x.Key + "=" + x.Value)));+ }+return _appHost.Name;}diff --git a/Jellyfin.Server/Middleware/UrlDecodeQueryFeature.cs b/Jellyfin.Server/Middleware/UrlDecodeQueryFeature.csindex b18ba70512..44b30baac0 100644--- a/Jellyfin.Server/Middleware/UrlDecodeQueryFeature.cs+++ b/Jellyfin.Server/Middleware/UrlDecodeQueryFeature.cs@@ -66,7 +66,14 @@ namespace Jellyfin.Server.Middlewareforeach (var pair in queryString){var item = pair.Split('=', System.StringSplitOptions.RemoveEmptyEntries);- pairs.Add(item[0], new StringValues(item.Length == 2 ? item[1] : string.Empty));+ if (item.Length > 0)+ {+ pairs.Add(item[0], new StringValues(item.Length == 2 ? item[1] : string.Empty));+ }+ else+ {+ pairs.Add(pair, string.Empty);+ }}_store = new QueryCollection(pairs);diff --git a/tests/Jellyfin.Api.Tests/Controllers/EncodedQueryStringTest.cs b/tests/Jellyfin.Api.Tests/Controllers/EncodedQueryStringTest.csnew file mode 100644index 0000000000..ce5ac11ea5--- /dev/null+++ b/tests/Jellyfin.Api.Tests/Controllers/EncodedQueryStringTest.cs@@ -0,0 +1,47 @@+using System.IO;+using System.Linq;+using System.Net;+using System.Net.Http;+using System.Text;+using System.Threading.Tasks;+using Xunit;++namespace Jellyfin.Api.Tests.Controllers+{+ /// <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;+ }++ [Fact]+ public async Task Ensure_Ping_Working()+ {+ var client = _factory.CreateClient();++ var response = await client.GetAsync("system/ping").ConfigureAwait(false);+ Assert.Equal(HttpStatusCode.OK, response.StatusCode);+ }++ [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("%3D", "==")] // will decode with an empty string 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("system/ping?" + sourceUrl).ConfigureAwait(false);+ Assert.Equal(HttpStatusCode.OK, response.StatusCode);+ Assert.Equal(unencodedUrl, response.Headers.GetValues("querystring").First());+ }+ }+}