Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect sorting of archives with uppercase/lowercase mixed files #652

Closed
kw4s opened this issue Jul 1, 2022 · 1 comment
Closed

Incorrect sorting of archives with uppercase/lowercase mixed files #652

kw4s opened this issue Jul 1, 2022 · 1 comment

Comments

@kw4s
Copy link

kw4s commented Jul 1, 2022

LRR Version and OS
LRR 0.8.5, Docker, Linux host

Bug Details
Current file sorting algorithm sorts files in ascii code order which means that for example file "h01.jpg" (which is expanded to h0001.jpg via "magical sort" expand function) will come after OK_002.jpg. Which is unfortunately not the correct order, not in windows filename sorting, not in linux filename sorting, not in any cbz/cbr viewer I've ever seen...
Some other examples: Z_02.jpg < h01.jpg < z_01.jpg

This issue causes some other problems - incorrect page order while reading, metadata providers not working correctly (because they rely on submitting cover page, and cover page was sorted to the end of archive...), thumbnail generation grabbing the wrong image, etc

Matching Logs
No logs, sorry, but I can give you this:

# current implementation of expand
sub expand {
    my $file = shift;
    $file =~ s{(\d+)}{sprintf "%04d", $1}eg;
    return $file;
}

# expand fixed with lowercase
sub expand_lc {
    my $file = shift;
    $file =~ s{(\d+)}{sprintf "%04d", $1}eg;
    return lc($file); # <- this thing right here
}


@files = ("z_01.jpg","h01.jpg", "h01_02.jpg",   "Z_02.jpg", "OK_003.jpg", "z_2.jpg");
@files = sort { &expand($a) cmp &expand($b) } @files;
print join(', ', @files), "\n";

@files = ("z_01.jpg","h01.jpg", "h01_02.jpg",   "Z_02.jpg", "OK_003.jpg", "z_2.jpg");
@files = sort { &expand_lc($a) cmp &expand_lc($b) } @files;
print join(', ', @files), "\n";

# original list:   z_01.jpg, h01.jpg, h01_02.jpg, Z_02.jpg, OK_003.jpg, z_2.jpg
# expand:          OK_003.jpg, Z_02.jpg, h01.jpg, h01_02.jpg, z_01.jpg, z_2.jpg
# expand_lc:       h01.jpg, h01_02.jpg, OK_003.jpg, z_01.jpg, Z_02.jpg, z_2.jpg

Screenshots
No screenshots.

@Difegue
Copy link
Owner

Difegue commented Jul 1, 2022

Huh, can't believe I've missed something that simple all this time.
Most of the time cbzs don't mixup case in their filenames, which is probably why it hasn't shown up too much. ¯\_(ツ)_/¯

Thanks a lot for the detailed repro and fix!

@Difegue Difegue closed this as completed Jul 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants