[BUG] Feed ordering within a category is inconsistent between the sidebar and the article list when titles mix CJK and ASCII characters
Description
When feeds within a category have names that mix CJK (Chinese/Japanese/Korean) and ASCII characters, the relative order of two feeds can be different between:
- the left sidebar (category → feed list), and
- the main article list, when article sorting is set to "Feed title A→Z" (
sort=f.name).
This happens even though both are supposedly "sorted by feed title."
Steps to reproduce
- Create a category containing (at least) two feeds whose names start with the same numeric/alphabetic prefix but diverge into different scripts, e.g.:
5 中文标题示例(continues in CJK after the shared prefix)5 English-Title-Example(continues in ASCII after the shared prefix)
- In Settings → Display → "Sorting criterion", select "Feed title A→Z".
- Compare the order of these two feeds in the left sidebar vs. the main article list.
Expected behavior
Both panels should show the two feeds in the same relative order, since both claim to sort by feed title.
Actual behavior
- Sidebar shows:
5 中文标题示例before5 English-Title-Example - Article list shows:
5 English-Title-Examplebefore5 中文标题示例
(exact relative order depends on your DB collation — see root cause below — but the two panels disagree with each other regardless of which order either one picks)
Root cause (traced in source)
Two independent, uncoordinated comparators are used for what looks like the same sort:
Sidebar — feeds are re-sorted in PHP after being fetched, regardless of the "Sorting criterion" setting:
// app/Models/Category.php:298-303 private function sortFeeds(): void { uasort($this->feeds, static fn(FreshRSS_Feed $a, FreshRSS_Feed $b) => strnatcasecmp($a->name(), $b->name())); }strnatcasecmp()performs a raw byte-wise comparison of the UTF-8 encoded string. ASCII bytes (0x20–0x7E) are numerically smaller than the lead byte of any multi-byte CJK UTF-8 sequence (≥0xE0), so this tends to sort ASCII text before CJK text.This function is called unconditionally from the
FreshRSS_Categoryconstructor via_feeds()(app/Models/Category.php:171-176), and never consultsFreshRSS_Context::$sort/ the "Sorting criterion" user setting.Article list — the
sort=f.nameoption translates directly into a SQLORDER BY, delegated entirely to the database engine's collation:// app/Models/EntryDAO.php ~1594-1600 $orderBy = match ($sort) { ... 'f.name' => 'f.name', ... };-- app/Models/EntryDAO.php ~1625-1642 ... FROM `_entry` e INNER JOIN `_feed` f ON f.id = e.id_feed ... ORDER BY f.name {order}, ...No PHP-side re-sort happens afterward — ordering is 100% delegated to the DB's collation on
_feed.name. The default schema declares this table under a collation ofutf8mb4_unicode_cifor MySQL (app/SQL/install.sql.mysql.php:24,40), which uses Unicode linguistic weighting — not the same rule as PHP's byte comparison.Because
strnatcasecmp()(byte-wise) andutf8mb4_unicode_ci(linguistic collation) don't agree on how to interleave ASCII vs. CJK, two feed names identical up to a shared prefix but diverging into different scripts can end up in opposite relative order between the two panels.Verified independently:
$ php -r 'var_dump(strnatcasecmp("5 中文标题示例","5 English-Title-Example"));' int(1) // PHP byte comparison puts the ASCII string first-- utf8mb4_unicode_ci SELECT name FROM feed ORDER BY name COLLATE utf8mb4_unicode_ci; -- CJK can sort BEFORE ASCII here, opposite of the PHP comparator above
Additionally, the "Sorting criterion" setting is only wired into indexController → EntryDAO (the article list); Category::sortFeeds() never reads it, so changing this setting has zero visible effect on the sidebar's feed order.
Suggested fix (either direction would make the two panels consistent)
- Make
Category::sortFeeds()aware ofFreshRSS_Context::$sort(or at least use the same collation semantics as the SQL query), or - Make the article-list
ORDER BY f.nameuse an explicit collation matching PHP'sstrnatcasecmpbyte ordering (e.g.COLLATE utf8mb4_binon MySQL), for consistency across DB backends (MySQL/PostgreSQL/SQLite all have different default collations here, which is a related but broader consistency question).
Environment
- FreshRSS version:
edgebranch - DB backend: (please fill in / comment with yours — MySQL / PostgreSQL / SQLite, and DB collation if MySQL)
- Reproduced via: reading
app/Models/Category.phpandapp/Models/EntryDAO.phpin the currentedgebranch source.
Source: FreshRSS/FreshRSS