diff options
author | Matthew Holt <[email protected]> | 2019-11-11 19:29:31 -0700 |
---|---|---|
committer | Matthew Holt <[email protected]> | 2019-11-11 19:29:31 -0700 |
commit | ad90b273dbb13bf45644f39f6c0be1248c943d9a (patch) | |
tree | 04dbcbd3a90c3a0d3bb33b21b8e8474d35e59236 /replacer.go | |
parent | 93bc1b72e3cd566e6447ad7a1f832474aad5dfcc (diff) | |
download | caddy-ad90b273dbb13bf45644f39f6c0be1248c943d9a.tar.gz caddy-ad90b273dbb13bf45644f39f6c0be1248c943d9a.zip |
core: Add tests to Replacer; fix panic (fixes #2852)
Diffstat (limited to 'replacer.go')
-rw-r--r-- | replacer.go | 9 |
1 files changed, 6 insertions, 3 deletions
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] |