core: Add tests to Replacer; fix panic (fixes #2852)

This commit is contained in:
Matthew Holt 2019-11-11 19:29:31 -07:00
parent 93bc1b72e3
commit ad90b273db
No known key found for this signature in database
GPG key ID: 2A349DD577D586A5
2 changed files with 67 additions and 10 deletions

View file

@ -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]