Shopify / Shopify/liquid

sort_natural does no natural sort

Open
#1,446 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
11.9k
Forks
1.5k
Avg merge
17h 55m
Merged PRs (30d)
3

Description

sort_natural is able to sort case-insensitively but does not sort numbers in the expected way.

The sort would e.g. return

  • 10,11,2,3,4 instead of the expected 2,3,4,10,11
  • z11,z2 instead of the expected z2,z11

The overall definition of "natural" sort seems to be "how a human would sort the list", so it is a little vague. But the consensus seems to be that natural sorting should sort by numbers, not by characters:

The fallout is, e.g. that navigation lists sorted by liquid are in the wrong order. This is done in multiple Jekyll themes, for example

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the sort_natural implementation and any tests covering its ordering behavior. Verify the current results against the examples in the issue, then update the behavior so numeric portions sort by value, including values such as 10, 11, 2 and z11, z2; done means these cases produce the expected natural order.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.