Files are not sorted alphabetically #13154

Closed
opened 2025-11-02 10:32:57 -06:00 by GiteaMirror · 5 comments
Owner

Originally created by @ParticleCore on GitHub (Jun 14, 2024).

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

Originally created by @ParticleCore on GitHub (Jun 14, 2024). ### 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](https://github.com/go-gitea/gitea/assets/9222661/18e6617b-2b38-4145-8652-a97ac540bcfb) Demo ![Screenshot 2024-06-14 085520](https://github.com/go-gitea/gitea/assets/9222661/6dad32fa-b7d2-494d-850d-5c33e6bc95d4) ### 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
GiteaMirror added the issue/confirmedtype/bugtopic/ui labels 2025-11-02 10:32:58 -06:00
Author
Owner

@wxiaoguang commented on GitHub (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 commented on GitHub (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 ..... * https://github.com/golang/go/issues/67997
Author
Owner

@ParticleCore commented on GitHub (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.

@ParticleCore commented on GitHub (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](https://github.com/go-gitea/gitea/assets/9222661/1fd18581-ca13-4d3d-b880-dad1118ba959) 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.
Author
Owner

@wxiaoguang commented on GitHub (Jun 14, 2024):

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

@wxiaoguang commented on GitHub (Jun 14, 2024): ` 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`
Author
Owner

@ParticleCore commented on GitHub (Jun 14, 2024):

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.

@ParticleCore commented on GitHub (Jun 14, 2024): > ` 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.
Author
Owner

@wxiaoguang commented on GitHub (Jun 15, 2024):

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

@wxiaoguang commented on GitHub (Jun 15, 2024): Before Golang fixes their bug, let's try this: Fix natural sort #31384
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#13154