Skip to content

fix(sort): explorer-like ordering for leading-zero prefixes - #3047

Merged
AlexAndBear merged 1 commit into
mainfrom
issues/2993-2
Aug 7, 2026
Merged

fix(sort): explorer-like ordering for leading-zero prefixes#3047
AlexAndBear merged 1 commit into
mainfrom
issues/2993-2

Conversation

@AlexAndBear

@AlexAndBear AlexAndBear commented Aug 6, 2026

Copy link
Copy Markdown
Member

Summary

Fixes sorting for files and folders with leading-zero prefixes (e.g., 00000_*, 0000_*, 00_*, 0_*) to match Windows Explorer behavior.

Problem

The web client uses natural sorting with Intl.Collator and numeric: true, which treats different numbers of leading zeros as the same numeric value (0). This breaks intentional ordering schemes where users rely on distinct zero prefixes to organize their files.

Example: 00000_Important, 0000_Archive, 00_Projects, 0_Other were all treated as starting with 0 and sorted only by the text after the prefix.

Solution

Added special handling in useSort.ts for names with leading-zero prefixes:

  1. Detection: Regex ^(0+)(?!\d)(.*)$ identifies pure zero prefixes
  2. Comparison priority:
    • Compare by prefix length (more zeros → higher priority)
    • Then compare suffixes using natural sorting
    • Use full name as tie-breaker
  3. Fallback: Names without zero prefixes use existing natural sorting

Examples

With fix (ascending):

  • 00000_ITEM_ALPHA
  • 0000_BLOCK_ALPHA
  • 00_SET_ALPHA
  • 0_NODE_ALPHA

Regular names still work naturally:

  • file1, file01, file001, file2, file02, ...

What Stays the Same

  • Folder/file grouping unchanged
  • Non-name sort fields unchanged
  • Extension handling unchanged

Testing

  • Extended useSort.spec.ts with anonymized zero-prefix datasets
  • Verified ascending/descending order for both files and folders
  • Existing natural sorting tests still pass

Closes #2993

@AlexAndBear
AlexAndBear force-pushed the issues/2993-2 branch 4 times, most recently from b321bc0 to 0442e1b Compare August 6, 2026 15:57
@AlexAndBear AlexAndBear self-assigned this Aug 6, 2026
@AlexAndBear
AlexAndBear merged commit 586ccdd into main Aug 7, 2026
30 checks passed
@AlexAndBear
AlexAndBear deleted the issues/2993-2 branch August 7, 2026 07:21
@openclouders openclouders mentioned this pull request Aug 7, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Web client ignores leading zeros when sorting by name

2 participants