Bug: Using .Get with non-existent .Params returns an empty string instead of nil

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.

Summary of findings:

Using .Get with non-existent .Params returns an empty string instead of nil. This occurs with either named or positional parameters.

The correct result (nil) is obtained when accessing the .Params map directly.

The isset function returns the correct result with non-existent .Params.


{{< myshortcode other="bar" >}}

{{< myshortcode "bar" >}}


{{ if .IsNamedParams }}
  {{ warnf "A %#v" (.Get "foo") }}          --> ""
  {{ warnf "B %#v" (.Params.foo) }}         --> nil
  {{ warnf "C %#v" (index .Params "foo") }} --> nil
  {{ warnf "D %#v" (isset .Params "foo") }} --> false
{{ else }}
  {{ warnf "E %#v" (.Get 1) }}              --> ""
  {{ warnf "F %#v" (index .Params 1) }}     --> nil
  {{ warnf "G %#v" (isset .Params 1) }}     --> false
{{ end }}

So it seems like this is a bug, but .Get has behaved this way for years without complaints. What impact does this have on what you are trying to accomplish?

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.

If you feel strongly about it, please raise an issue on GH.