Skip to content

text/template: pointers to strings #5802

@robpike

Description

@robpike
package main

import (
    "os"
    "text/template"
)

type T struct {
    D *string
}

func main() {
    t, err := template.New("x").Parse("{{html .D}}")
    if err != nil { panic(err) }
    d := "hi\n"
    err = t.Execute(os.Stdout, T{&d})
    if err != nil { panic(err) }
}

One feels this should print "hi" but instead it prints the hex address of the
string. Ugly.

What should be done? Should functions autoindirect their args? Should template provide
an indirection operator? Tread carefully but fix.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions