Skip to content

text/template: template function index should permit integer values of float type #17236

@willfaught

Description

@willfaught

The text/template function index should permit integer values of float type as indexes, since there's no way to convert types in templates themselves.

I hit this particular problem when using unmarshaled JSON as the template data, similar to what's done in the play link below, where an integer in one part refers to an index of a list in another part, but when parsed, the integer is converted to float64.

Note that the function eq is also loose with types.

What did you do?

https://play.golang.org/p/_9K1wu6THk

What did you expect to see?

9

What did you see instead?

template: :1:2: executing "" at <index .a .b>: error calling index: cannot index slice/array with type float64

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions