From b1994691014541359bd69047b2ee2e39d878bf5b Mon Sep 17 00:00:00 2001 From: sb123sb123 <152394158+sb123sb123@users.noreply.github.com> Date: Tue, 22 Sep 2026 00:31:15 +0800 Subject: [PATCH] fix: stringify string pointers correctly --- strings.go | 5 +++++ strings_test.go | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/strings.go b/strings.go index e0ae628c..aa4b4a2a 100644 --- a/strings.go +++ b/strings.go @@ -175,6 +175,11 @@ func strval(v interface{}) string { switch v := v.(type) { case string: return v + case *string: + if v == nil { + return "" + } + return *v case []byte: return string(v) case error: diff --git a/strings_test.go b/strings_test.go index 28b9a1e8..c05801f9 100644 --- a/strings_test.go +++ b/strings_test.go @@ -146,6 +146,14 @@ func TestToString(t *testing.T) { } } +func TestToStringPointers(t *testing.T) { + value := "pointer" + assert.NoError(t, runtv(`{{ toString .Value }}`, "pointer", map[string]interface{}{"Value": &value})) + + var nilValue *string + assert.NoError(t, runtv(`{{ toString .Value }}`, "", map[string]interface{}{"Value": nilValue})) +} + func TestToStrings(t *testing.T) { tpl := `{{ $s := list 1 2 3 | toStrings }}{{ index $s 1 | kindOf }}` assert.NoError(t, runt(tpl, "string"))