mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Merge pull request #12698 from jellyfin/fix-libraryoptions-api
Sanitize CustomTagDelimiters server side
This commit is contained in:
commit
30be00adb2
@ -2,12 +2,13 @@
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
|
||||
namespace MediaBrowser.Model.Configuration
|
||||
{
|
||||
public class LibraryOptions
|
||||
{
|
||||
private static readonly char[] _defaultTagDelimiters = ['/', '|', ';', '\\'];
|
||||
private static readonly string[] _defaultTagDelimiters = ["/", "|", ";", "\\"];
|
||||
|
||||
public LibraryOptions()
|
||||
{
|
||||
@ -126,8 +127,7 @@ namespace MediaBrowser.Model.Configuration
|
||||
[DefaultValue(false)]
|
||||
public bool UseCustomTagDelimiters { get; set; }
|
||||
|
||||
[DefaultValue(typeof(LibraryOptions), nameof(_defaultTagDelimiters))]
|
||||
public char[] CustomTagDelimiters { get; set; }
|
||||
public string[] CustomTagDelimiters { get; set; }
|
||||
|
||||
public string[] DelimiterWhitelist { get; set; }
|
||||
|
||||
|
32
MediaBrowser.Model/Extensions/LibraryOptionsExtension.cs
Normal file
32
MediaBrowser.Model/Extensions/LibraryOptionsExtension.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using MediaBrowser.Model.Configuration;
|
||||
|
||||
namespace MediaBrowser.Model.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Extensions for <see cref="LibraryOptions"/>.
|
||||
/// </summary>
|
||||
public static class LibraryOptionsExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// Get the custom tag delimiters.
|
||||
/// </summary>
|
||||
/// <param name="options">This LibraryOptions.</param>
|
||||
/// <returns>CustomTagDelimiters in char[].</returns>
|
||||
public static char[] GetCustomTagDelimiters(this LibraryOptions options)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(options);
|
||||
|
||||
return options.CustomTagDelimiters.Select<string, char?>(x =>
|
||||
{
|
||||
var isChar = char.TryParse(x, out var c);
|
||||
if (isChar)
|
||||
{
|
||||
return c;
|
||||
}
|
||||
|
||||
return null;
|
||||
}).Where(x => x is not null).Select(x => x!.Value).ToArray();
|
||||
}
|
||||
}
|
@ -16,6 +16,7 @@ using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Dlna;
|
||||
using MediaBrowser.Model.Dto;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Extensions;
|
||||
using MediaBrowser.Model.MediaInfo;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
@ -178,7 +179,7 @@ namespace MediaBrowser.Providers.MediaInfo
|
||||
|
||||
if (libraryOptions.UseCustomTagDelimiters)
|
||||
{
|
||||
albumArtists = albumArtists.SelectMany(a => SplitWithCustomDelimiter(a, libraryOptions.CustomTagDelimiters, libraryOptions.DelimiterWhitelist)).ToArray();
|
||||
albumArtists = albumArtists.SelectMany(a => SplitWithCustomDelimiter(a, libraryOptions.GetCustomTagDelimiters(), libraryOptions.DelimiterWhitelist)).ToArray();
|
||||
}
|
||||
|
||||
foreach (var albumArtist in albumArtists)
|
||||
@ -210,7 +211,7 @@ namespace MediaBrowser.Providers.MediaInfo
|
||||
|
||||
if (libraryOptions.UseCustomTagDelimiters)
|
||||
{
|
||||
performers = performers.SelectMany(p => SplitWithCustomDelimiter(p, libraryOptions.CustomTagDelimiters, libraryOptions.DelimiterWhitelist)).ToArray();
|
||||
performers = performers.SelectMany(p => SplitWithCustomDelimiter(p, libraryOptions.GetCustomTagDelimiters(), libraryOptions.DelimiterWhitelist)).ToArray();
|
||||
}
|
||||
|
||||
foreach (var performer in performers)
|
||||
@ -313,7 +314,7 @@ namespace MediaBrowser.Providers.MediaInfo
|
||||
|
||||
if (libraryOptions.UseCustomTagDelimiters)
|
||||
{
|
||||
genres = genres.SelectMany(g => SplitWithCustomDelimiter(g, libraryOptions.CustomTagDelimiters, libraryOptions.DelimiterWhitelist)).ToArray();
|
||||
genres = genres.SelectMany(g => SplitWithCustomDelimiter(g, libraryOptions.GetCustomTagDelimiters(), libraryOptions.DelimiterWhitelist)).ToArray();
|
||||
}
|
||||
|
||||
audio.Genres = options.ReplaceAllMetadata || audio.Genres is null || audio.Genres.Length == 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user