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

Files are not sorted alphabetically #31374

Closed
ParticleCore opened this issue Jun 14, 2024 · 5 comments · Fixed by #31384
Closed

Files are not sorted alphabetically #31374

ParticleCore opened this issue Jun 14, 2024 · 5 comments · Fixed by #31384
Labels
issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented topic/ui Change the appearance of the Gitea UI type/bug

Comments

@ParticleCore
Copy link

Description

Currently trying to have a folder with files that are sorted alphabetically, but the web interface does not sort it correctly.

I already tried uploading each version by alphabetical order individually, I also modified each file in temporal order in case the modified time might be influencing the order, but nothing works, it always keeps the same incorrect order.

Items from 1 to 9 are always sorted correctly, but anything with the 0 is positioned after 9 instead of before 1.

I cannot find any way to fix this, so I am filing it as a bug.

I am able to reproduce this problem on the demo site as well: https://gitea.com/ParticleCore/sortorder

Attached follows screenshots of the problem on the private repo and demo site

Screenshots

Private
Screenshot 2024-06-14 084743

Demo
Screenshot 2024-06-14 085520

Gitea Version

1.22.0

Can you reproduce the bug on the Gitea demo site?

Yes

Operating System

No response

Browser Version

Firefox Stable latest

@ParticleCore ParticleCore added topic/ui Change the appearance of the Gitea UI type/bug labels Jun 14, 2024
@wxiaoguang
Copy link
Contributor

wxiaoguang commented Jun 14, 2024

It's related to this function:

func NaturalSortLess(s1, s2 string) bool {
	c := collate.New(language.English, collate.Numeric)
	return c.CompareString(s1, s2) < 0
}

Golang considers 0.0 > 1.1 (also 0.txt > 1.txt), strange .....

@wxiaoguang wxiaoguang added the issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented label Jun 14, 2024
@ParticleCore
Copy link
Author

ParticleCore commented Jun 14, 2024

I am assuming that means strictly comparing numbers ("0", "1", "2", etc.) will not have this problem, but when the numbers are mixed with text the problem surfaces. If that is the case it could be because internally CompareString is converting the 0 number into a different equivalent code that has a higher position than 1...9.

I did check unicode and ASCII tables to see if 0 would be position after 9 but so far nothing, the only place I found where that happens is on the numeric row of the keyboard layouts.

I also did a simple test with an online terminal and I got a different result than the one linked in your issue

image

collate version 0.16.0 to 0.7.0
https://pkg.go.dev/golang.org/x/text/collate#example-Collator.CompareString

So I am not sure why it is giving different results between the web terminal and local install.

UPDATE: I actually forgot to include collate.Numeric in my previous tests, but when I did that all collate versions down to 0.7.0 at least had the same problem as yours.

However, when I don't use collate.Numeric then it seems like it works ok for everything.

@wxiaoguang
Copy link
Contributor

c := collate.New(language.English, collate.Numeric)

collate.Numeric means:

	// numeric specifies whether any sequence of decimal digits (category is Nd)
	// is sorted at a primary level with its numeric value.
	// For example, "A-21" < "A-123".

So v2.0 < v10.0

@ParticleCore
Copy link
Author

c := collate.New(language.English, collate.Numeric)

collate.Numeric means:

	// numeric specifies whether any sequence of decimal digits (category is Nd)
	// is sorted at a primary level with its numeric value.
	// For example, "A-21" < "A-123".

So v2.0 < v10.0

Yep, just realized it and retested again and got the same results as yours, I updated my previous entry to mention that.

@wxiaoguang
Copy link
Contributor

Before Golang fixes their bug, let's try this: Fix natural sort #31384

wxiaoguang added a commit that referenced this issue Jun 17, 2024
GiteaBot pushed a commit to GiteaBot/gitea that referenced this issue Jun 17, 2024
wxiaoguang added a commit that referenced this issue Jun 17, 2024
Backport #31384 by wxiaoguang

Fix #31374

Co-authored-by: wxiaoguang <[email protected]>
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Sep 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented topic/ui Change the appearance of the Gitea UI type/bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants