Merge pull request #17402 from Shadowghost/clean-forced-sort-name

Apply cleaning logic on ForcedSortName
This commit is contained in:
Cody Robibero
2026-07-24 21:34:37 -04:00
committed by GitHub
3 changed files with 166 additions and 9 deletions
@@ -4,10 +4,12 @@ using System.Linq;
using System.Reflection;
using System.Threading;
using Jellyfin.Database.Implementations.Entities;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Controller.MediaSegments;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.MediaInfo;
@@ -28,6 +30,35 @@ public class BaseItemTests
public void BaseItem_ModifySortChunks_Valid(string input, string expected)
=> Assert.Equal(expected, BaseItem.ModifySortChunks(input));
[Theory]
[InlineData("The Matrix", "matrix")]
[InlineData("Spider-Man", "spiderman")]
[InlineData("A Movie: Part 2", "movie: part 0000000002")]
public void GetSortName_AppliesConfiguredCleaning(string input, string expected)
=> Assert.Equal(expected, BaseItem.GetSortName(input, true, new ServerConfiguration()));
[Fact]
public void GetSortName_WithoutAlphaNumericSorting_ReturnsTrimmedInput()
=> Assert.Equal("The Matrix", BaseItem.GetSortName(" The Matrix", false, new ServerConfiguration()));
[Fact]
public void SortName_ForcedSortName_IsCleanedLikeAutoSortName()
{
var configManager = new Mock<IServerConfigurationManager>();
configManager.Setup(x => x.Configuration).Returns(new ServerConfiguration());
BaseItem.ConfigurationManager = configManager.Object;
const string Raw = "The Spider-Man: Homecoming";
var auto = new Video { Name = Raw };
var forced = new Video { Name = "zzz unrelated name", ForcedSortName = Raw };
// A forced sort name must be cleaned the same way as an auto-generated one so both sort together (#17388).
Assert.Equal(auto.SortName, forced.SortName);
// Sanity: cleaning actually ran (leading article and hyphen removed, colon kept, lowercased).
Assert.Equal("spiderman: homecoming", forced.SortName);
}
[Theory]
[InlineData("/Movies/Ted/Ted.mp4", "/Movies/Ted/Ted - Unrated Edition.mp4", "Ted", "Unrated Edition")]
[InlineData("/Movies/Deadpool 2 (2018)/Deadpool 2 (2018).mkv", "/Movies/Deadpool 2 (2018)/Deadpool 2 (2018) - Super Duper Cut.mkv", "Deadpool 2 (2018)", "Super Duper Cut")]