summaryrefslogtreecommitdiff
path: root/replacer.go
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2022-09-01 21:15:20 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2022-09-01 21:15:44 -0600
commit73d4a8ba02292491fca289b324e89ef8c62fd435 (patch)
treedf0ce2fd72c75b03490c28686402f3f67d9e9eea /replacer.go
parent7d5108d132d3bccfd8d83bc3fc2dbc46afde20ae (diff)
map: Coerce val to string, fix #4987
Also prevent infinite recursion, and enforce placeholder syntax.
Diffstat (limited to 'replacer.go')
-rw-r--r--replacer.go12
1 files changed, 7 insertions, 5 deletions
diff --git a/replacer.go b/replacer.go
index aa943cf..d30a406 100644
--- a/replacer.go
+++ b/replacer.go
@@ -78,11 +78,11 @@ func (r *Replacer) Get(variable string) (any, bool) {
return nil, false
}
-// GetString is the same as Get, but coerces the value to a
-// string representation.
+// GetString is the same as Get, but coerces the value to a
+// string representation as efficiently as possible.
func (r *Replacer) GetString(variable string) (string, bool) {
s, found := r.Get(variable)
- return toString(s), found
+ return ToString(s), found
}
// Delete removes a variable with a static value
@@ -204,7 +204,7 @@ scan:
}
// convert val to a string as efficiently as possible
- valStr := toString(val)
+ valStr := ToString(val)
// write the value; if it's empty, either return
// an error or write a default value
@@ -230,7 +230,9 @@ scan:
return sb.String(), nil
}
-func toString(val any) string {
+// ToString returns val as a string, as efficiently as possible.
+// EXPERIMENTAL: may be changed or removed later.
+func ToString(val any) string {
switch v := val.(type) {
case nil:
return ""