#9321·FreshRSS

[BUG] Feed ordering within a category is inconsistent between the sidebar and the article list when titles mix CJK and ASCII characters

Author: iatmanCreated Sep 19, 2026Updated Sep 22, 2026

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

  1. 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)
  2. In Settings → Display → "Sorting criterion", select "Feed title A→Z".
  3. 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 中文标题示例 before 5 English-Title-Example
  • Article list shows: 5 English-Title-Example before 5 中文标题示例

(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:

  1. Sidebar — feeds are re-sorted in PHP after being fetched, regardless of the "Sorting criterion" setting:

    php
    // 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_Category constructor via _feeds() (app/Models/Category.php:171-176), and never consults FreshRSS_Context::$sort / the "Sorting criterion" user setting.

  2. Article list — the sort=f.name option translates directly into a SQL ORDER BY, delegated entirely to the database engine's collation:

    php
    // app/Models/EntryDAO.php ~1594-1600
    $orderBy = match ($sort) {
        ...
        'f.name' => 'f.name',
        ...
    };
    sql
    -- 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 of utf8mb4_unicode_ci for MySQL (app/SQL/install.sql.mysql.php:24,40), which uses Unicode linguistic weighting — not the same rule as PHP's byte comparison.

  3. Because strnatcasecmp() (byte-wise) and utf8mb4_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
    sql
    -- 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 of FreshRSS_Context::$sort (or at least use the same collation semantics as the SQL query), or
  • Make the article-list ORDER BY f.name use an explicit collation matching PHP's strnatcasecmp byte ordering (e.g. COLLATE utf8mb4_bin on 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: edge branch
  • DB backend: (please fill in / comment with yours — MySQL / PostgreSQL / SQLite, and DB collation if MySQL)
  • Reproduced via: reading app/Models/Category.php and app/Models/EntryDAO.php in the current edge branch source.