craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.25k stars 629 forks source link

[3.x]: Project.yaml sorting is odd #12710

Open gbowne-quickbase opened 1 year ago

gbowne-quickbase commented 1 year ago

What happened?

Description

We're seeing some weird behavior where sorting is not being treated as numeric hex values but as string/hex hybrids, and this leading zero is not taken into account

image

Steps to reproduce

  1. Create a field with a hex value that starts with a leading zero
  2. See where it's sorted within the project.yaml file

Expected behavior

  1. We'd see this sorted with similar other leading zero hex values

Actual behavior

  1. We see this sorted as though the leading zero isn't there

Craft CMS version

3.7.65.2

PHP version

7.4.33

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

-

brandonkelly commented 1 year ago

Associative arrays are sorted with ksort() using the SORT_NATURAL sorting method:

https://github.com/craftcms/cms/blob/abd397810c6cefd2c80aa812d1a186d63807edfd/src/helpers/ProjectConfig.php#L191

Guessing that SORT_NATURAL is not doing anything special for UUIDs, because they aren’t completely numeric.

The strange part to me about that diff is how the keys would have ended up in the original order, as 0 definitely feels like it should come before 2 when ordering things “natuarlly”.