From 713a485e6f0b53ebf5e21019b2b10def8d87165c Mon Sep 17 00:00:00 2001 From: Solaris-star <820622658@qq.com> Date: Tue, 21 Jul 2026 13:32:42 +0800 Subject: [PATCH] docs: clarify quote/squote escaping behavior Document that quote uses Go %q escaping (not only wrapping) and that squote only adds surrounding single quotes without Go string escaping. Fixes #481 --- docs/strings.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/strings.md b/docs/strings.md index 2e0f455d..cbb6c3f4 100644 --- a/docs/strings.md +++ b/docs/strings.md @@ -234,6 +234,29 @@ The above returns `true` because `catch` has the prefix `cat`. These functions wrap a string in double quotes (`quote`) or single quotes (`squote`). +`quote` also escapes the string contents using Go's `%q` verb +(`fmt.Sprintf("%q", ...)`), so the result is a double-quoted string that is +safely escaped with Go syntax (backslashes, quotes, and non-printable runes). +It is appropriate when generating Go string literals and is commonly used in +Helm charts for YAML scalar values. + +`squote` wraps each value in single quotes. Unlike `quote`, it does **not** +apply Go `%q` escaping to the contents; only the surrounding single quotes are +added. Prefer `quote` when the value may contain quotes or special characters +and you need safe escaping. + +``` +quote "Hello, world!" +``` + +The above produces `"Hello, world!"`. + +``` +squote "Hello, world!" +``` + +The above produces `'Hello, world!'`. + ## cat The `cat` function concatenates multiple strings together into one, separating