aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Api/Middleware/UrlDecodeQueryFeature.cs
diff options
context:
space:
mode:
authorShadowghost <Ghost_of_Stone@web.de>2023-01-31 12:18:10 +0100
committerShadowghost <Ghost_of_Stone@web.de>2023-02-02 18:50:33 +0100
commitf5f890e68562e55d4bed16c454c4b4305152b296 (patch)
treeb52e3b45ceb2faa446153866600b4456fed44c8b /Jellyfin.Api/Middleware/UrlDecodeQueryFeature.cs
parent58b3945805db4f88bc069ee84013bdf85d7429b1 (diff)
Migrate to file-scoped namespaces
Diffstat (limited to 'Jellyfin.Api/Middleware/UrlDecodeQueryFeature.cs')
-rw-r--r--Jellyfin.Api/Middleware/UrlDecodeQueryFeature.cs103
1 files changed, 51 insertions, 52 deletions
diff --git a/Jellyfin.Api/Middleware/UrlDecodeQueryFeature.cs b/Jellyfin.Api/Middleware/UrlDecodeQueryFeature.cs
index d35e0fcfd..f75d0d24e 100644
--- a/Jellyfin.Api/Middleware/UrlDecodeQueryFeature.cs
+++ b/Jellyfin.Api/Middleware/UrlDecodeQueryFeature.cs
@@ -6,79 +6,78 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.Extensions.Primitives;
-namespace Jellyfin.Api.Middleware
+namespace Jellyfin.Api.Middleware;
+
+/// <summary>
+/// Defines the <see cref="UrlDecodeQueryFeature"/>.
+/// </summary>
+public class UrlDecodeQueryFeature : IQueryFeature
{
+ private IQueryCollection? _store;
+
/// <summary>
- /// Defines the <see cref="UrlDecodeQueryFeature"/>.
+ /// Initializes a new instance of the <see cref="UrlDecodeQueryFeature"/> class.
/// </summary>
- public class UrlDecodeQueryFeature : IQueryFeature
+ /// <param name="feature">The <see cref="IQueryFeature"/> instance.</param>
+ public UrlDecodeQueryFeature(IQueryFeature feature)
{
- private IQueryCollection? _store;
+ Query = feature.Query;
+ }
- /// <summary>
- /// Initializes a new instance of the <see cref="UrlDecodeQueryFeature"/> class.
- /// </summary>
- /// <param name="feature">The <see cref="IQueryFeature"/> instance.</param>
- public UrlDecodeQueryFeature(IQueryFeature feature)
+ /// <summary>
+ /// Gets or sets a value indicating the url decoded <see cref="IQueryCollection"/>.
+ /// </summary>
+ public IQueryCollection Query
+ {
+ get
{
- Query = feature.Query;
+ return _store ?? QueryCollection.Empty;
}
- /// <summary>
- /// Gets or sets a value indicating the url decoded <see cref="IQueryCollection"/>.
- /// </summary>
- public IQueryCollection Query
+ set
{
- get
+ // Only interested in where the querystring is encoded which shows up as one key with nothing in the value.
+ if (value.Count != 1)
{
- return _store ?? QueryCollection.Empty;
+ _store = value;
+ return;
}
- set
+ // Encoded querystrings have no value, so don't process anything if a value is present.
+ var (key, stringValues) = value.First();
+ if (!string.IsNullOrEmpty(stringValues))
{
- // Only interested in where the querystring is encoded which shows up as one key with nothing in the value.
- if (value.Count != 1)
- {
- _store = value;
- return;
- }
+ _store = value;
+ return;
+ }
- // Encoded querystrings have no value, so don't process anything if a value is present.
- var (key, stringValues) = value.First();
- if (!string.IsNullOrEmpty(stringValues))
- {
- _store = value;
- return;
- }
+ if (!key.Contains('=', StringComparison.Ordinal))
+ {
+ _store = value;
+ return;
+ }
- if (!key.Contains('=', StringComparison.Ordinal))
+ var pairs = new Dictionary<string, StringValues>();
+ foreach (var pair in key.SpanSplit('&'))
+ {
+ var i = pair.IndexOf('=');
+ if (i == -1)
{
- _store = value;
- return;
+ // encoded is an equals.
+ // We use TryAdd so duplicate keys get ignored
+ pairs.TryAdd(pair.ToString(), StringValues.Empty);
+ continue;
}
- var pairs = new Dictionary<string, StringValues>();
- foreach (var pair in key.SpanSplit('&'))
+ var k = pair[..i].ToString();
+ var v = pair[(i + 1)..].ToString();
+ if (!pairs.TryAdd(k, new StringValues(v)))
{
- var i = pair.IndexOf('=');
- if (i == -1)
- {
- // encoded is an equals.
- // We use TryAdd so duplicate keys get ignored
- pairs.TryAdd(pair.ToString(), StringValues.Empty);
- continue;
- }
-
- var k = pair[..i].ToString();
- var v = pair[(i + 1)..].ToString();
- if (!pairs.TryAdd(k, new StringValues(v)))
- {
- pairs[k] = StringValues.Concat(pairs[k], v);
- }
+ pairs[k] = StringValues.Concat(pairs[k], v);
}
-
- _store = new QueryCollection(pairs);
}
+
+ _store = new QueryCollection(pairs);
}
}
}