From 9693f11fe5507a005fc7fcd0e30ef918ab1f214d Mon Sep 17 00:00:00 2001 From: Piotr Niełacny Date: Tue, 10 Mar 2026 16:53:12 +0100 Subject: Fix NameStartsWith filter not matching numeric item names The NameStartsWith, NameStartsWithOrGreater, and NameLessThan API filters compare user input against the internal SortName, which zero-pads numbers to 10 digits for natural sorting. This caused numeric filters like NameStartsWith=1 to fail because "1" doesn't match the padded sort name "0000000012...". Normalize filter input through ModifySortChunks before comparison so that padding is applied consistently. For NameStartsWith, add a TrimStart('0') fallback so that numeric prefixes like "1" correctly match sort names such as "0000000012 years a slave". Add NormalizeSortNameFilter helper on BaseItem and make ModifySortChunks public. Add unit tests covering numeric, alphabetic, and mixed prefix matching for all three filter types. Fixes #1470 --- .../Item/BaseItemRepository.QueryBuilding.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'Jellyfin.Server.Implementations/Item/BaseItemRepository.QueryBuilding.cs') diff --git a/Jellyfin.Server.Implementations/Item/BaseItemRepository.QueryBuilding.cs b/Jellyfin.Server.Implementations/Item/BaseItemRepository.QueryBuilding.cs index a4de9feb05..3fc51bf332 100644 --- a/Jellyfin.Server.Implementations/Item/BaseItemRepository.QueryBuilding.cs +++ b/Jellyfin.Server.Implementations/Item/BaseItemRepository.QueryBuilding.cs @@ -197,20 +197,23 @@ public sealed partial class BaseItemRepository { if (!string.IsNullOrWhiteSpace(filter.NameStartsWith)) { - var nameStartsWithLower = filter.NameStartsWith.ToLowerInvariant(); - dbQuery = dbQuery.Where(e => e.SortName!.ToLower().StartsWith(nameStartsWithLower)); + var paddedPrefix = BaseItem.NormalizeSortNameFilter(filter.NameStartsWith); + var rawPrefix = filter.NameStartsWith.ToLowerInvariant(); + dbQuery = dbQuery.Where(e => + e.SortName!.ToLower().StartsWith(paddedPrefix) + || e.SortName!.ToLower().TrimStart('0').StartsWith(rawPrefix)); } if (!string.IsNullOrWhiteSpace(filter.NameStartsWithOrGreater)) { - var startsOrGreaterLower = filter.NameStartsWithOrGreater.ToLowerInvariant(); - dbQuery = dbQuery.Where(e => e.SortName!.ToLower().CompareTo(startsOrGreaterLower) >= 0); + var paddedValue = BaseItem.NormalizeSortNameFilter(filter.NameStartsWithOrGreater); + dbQuery = dbQuery.Where(e => e.SortName!.ToLower().CompareTo(paddedValue) >= 0); } if (!string.IsNullOrWhiteSpace(filter.NameLessThan)) { - var lessThanLower = filter.NameLessThan.ToLowerInvariant(); - dbQuery = dbQuery.Where(e => e.SortName!.ToLower().CompareTo(lessThanLower) < 0); + var paddedValue = BaseItem.NormalizeSortNameFilter(filter.NameLessThan); + dbQuery = dbQuery.Where(e => e.SortName!.ToLower().CompareTo(paddedValue) < 0); } return dbQuery; -- cgit v1.2.3