From ad90b273dbb13bf45644f39f6c0be1248c943d9a Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Mon, 11 Nov 2019 19:29:31 -0700 Subject: core: Add tests to Replacer; fix panic (fixes #2852) --- replacer.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'replacer.go') diff --git a/replacer.go b/replacer.go index c82d81dc0..a38cf5577 100644 --- a/replacer.go +++ b/replacer.go @@ -116,11 +116,14 @@ func (r *replacer) replace(input, empty string, continue } - // write the substring from the last cursor to this point - sb.WriteString(input[lastWriteCursor:i]) - // find the end of the placeholder end := strings.Index(input[i:], string(phClose)) + i + if end < i { + continue + } + + // write the substring from the last cursor to this point + sb.WriteString(input[lastWriteCursor:i]) // trim opening bracket key := input[i+1 : end] -- cgit v1.2.3