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

Using .Get with non-existent .Params returns an empty string instead of nil #10651

Open
willfaught opened this issue Jan 25, 2023 · 0 comments
Open

Comments

@willfaught
Copy link

It should be nil in both cases.

For example, given this shortcode:

{{ warnf "%#v %#v" (.Get 0) (.Get "foo") }}

For {{< myshortcode "bar" >}}, "bar" <nil> is logged.

For {{< myshortcode other="bar" >}}, <nil> "" is logged.

Note how the second value logged varies between cases, despite .Get "foo" not being assigned an argument in either case.

It didn’t cause a problem for me directly, but my concern is that someone might think that {{ if ne (.Get "foo") "" }} or {{ if ne (.Get "foo") nil }} are correct, when they might not be, depending on the argument syntax. The API should be clear and consistent on the values, regardless of whether {{ if .Get "foo" }} is the primary way of checking for given values.

See https://discourse.gohugo.io/t/bug-using-get-with-non-existent-params-returns-an-empty-string-instead-of-nil/42593/2 for the full context.

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

$ hugo env
hugo v0.110.0+extended darwin/amd64 BuildDate=unknown
GOOS="darwin"
GOARCH="amd64"
GOVERSION="go1.19.5"
github.com/sass/libsass="3.6.5"
github.com/webmproject/libwebp="v1.2.4"

Does this issue reproduce with the latest release?

Yes

@bep bep added this to the v0.112.0 milestone Feb 15, 2023
@bep bep modified the milestones: v0.112.0, v0.113.0 Apr 15, 2023
@bep bep modified the milestones: v0.113.0, v0.115.0 Jun 13, 2023
@bep bep modified the milestones: v0.115.0, v0.116.0 Jun 30, 2023
@bep bep modified the milestones: v0.116.0, v0.117.0 Aug 1, 2023
@bep bep modified the milestones: v0.117.0, v0.118.0 Aug 30, 2023
@bep bep modified the milestones: v0.118.0, v0.119.0 Sep 15, 2023
@bep bep modified the milestones: v0.119.0, v0.120.0 Oct 5, 2023
@bep bep modified the milestones: v0.120.0, v0.121.0 Oct 31, 2023
@bep bep modified the milestones: v0.121.0, v0.122.0 Dec 6, 2023
@bep bep modified the milestones: v0.122.0, v0.123.0, v0.124.0 Jan 27, 2024
@bep bep modified the milestones: v0.124.0, v0.125.0 Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants