aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server.Implementations/Item/BaseItemRepository.QueryBuilding.cs
diff options
context:
space:
mode:
authorPiotr Niełacny <piotr.nielacny@gmail.com>2026-03-10 16:53:12 +0100
committerPiotr Niełacny <piotr.nielacny@gmail.com>2026-07-29 10:41:41 +0200
commit9693f11fe5507a005fc7fcd0e30ef918ab1f214d (patch)
treead3eba15cc221d3e9d0fc531b4e82e2fc6b40244 /Jellyfin.Server.Implementations/Item/BaseItemRepository.QueryBuilding.cs
parentafb716566d04102fa6c8e1b12977d175db301081 (diff)
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
Diffstat (limited to 'Jellyfin.Server.Implementations/Item/BaseItemRepository.QueryBuilding.cs')
-rw-r--r--Jellyfin.Server.Implementations/Item/BaseItemRepository.QueryBuilding.cs15
1 files changed, 9 insertions, 6 deletions
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;