aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Api/Middleware/UrlDecodeQueryFeature.cs
diff options
context:
space:
mode:
authorCody Robibero <cody@robibe.ro>2023-02-04 10:21:49 -0700
committerGitHub <noreply@github.com>2023-02-04 10:21:49 -0700
commitd1af317d98a6190711af406af17b569844aebbd7 (patch)
tree3422bb577d2821a9798465439e983932690aa2e3 /Jellyfin.Api/Middleware/UrlDecodeQueryFeature.cs
parente0519189b25bc4605889e46d9583fea9aef41732 (diff)
parentdfea1229e12764a77f5d392194b1848f80b87042 (diff)
Merge pull request #9215 from Shadowghost/api-scoped-namespace
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);
}
}
}