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

When sorting a slice of strings (ascending), the literal "infinity" string always comes last #10389

Closed
maw246 opened this issue Oct 24, 2022 · 2 comments · Fixed by #10596
Closed

Comments

@maw246
Copy link

maw246 commented Oct 24, 2022

What version of Hugo are you using (hugo version)?

$ hugo version
hugo v0.104.3-58b824581360148f2d91f5cc83f69bd22c1aa331+extended linux/amd64 BuildDate=2022-10-04T14:25:23Z VendorInfo=gohugoio

Does this issue reproduce with the latest release?

Yes

Description of the Issue

Given a slice of strings, Hugo treats "infinity" as alphabetically last in the list. E.g.:

{{delimit (slice "foo" "bar" "infinity" "alpha" "beta" "zeta" "yaml" "xylophone" | sort ) ", "}}

Produces:

alpha, bar, beta, foo, xylophone, yaml, zeta, infinity

It seems like infinity is being treated as a numeric value despite being defined as a string among other strings.

@jmooring
Copy link
Member

Confirmed.

{{ slice "infinity" "z" "a" | sort }}  --> [a z infinity]

This isn't new behavior. Same results with v0.54.0.

acclassic added a commit to acclassic/hugo that referenced this issue Jan 2, 2023
When sorting strings a worng order is returned. This happens because the strings are first converted
to floating values to check whether or not they should be sorted as
floating values. When an error is returned the strings will be
handled as string literals.
No error will be returned when parsing Inf, Infinity or NaN (case insensitive) because they
will be coverted to special floating point values and therefore are
legal float values.
Now we check if the returned converted values are special floating
values and treat them as string literals.

Fixes gohugoio#10389
@bep bep closed this as completed in #10596 Jan 2, 2023
bep pushed a commit that referenced this issue Jan 2, 2023
When sorting strings a worng order is returned. This happens because the strings are first converted
to floating values to check whether or not they should be sorted as
floating values. When an error is returned the strings will be
handled as string literals.
No error will be returned when parsing Inf, Infinity or NaN (case insensitive) because they
will be coverted to special floating point values and therefore are
legal float values.
Now we check if the returned converted values are special floating
values and treat them as string literals.

Fixes #10389
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants