startRedactable adds the opening redaction marker.
()
| 220 | |
| 221 | // startRedactable adds the opening redaction marker. |
| 222 | func (b *Buffer) startRedactable() { |
| 223 | if bytes.HasSuffix(b.buf, m.EndBytes) { |
| 224 | // Optimization: merge adjacent unsafe zones by removing the |
| 225 | // trailing › instead of writing a new ‹. However, we must NOT |
| 226 | // merge into a hash zone (‹†...›), because that would cause the |
| 227 | // next value to be hashed together with the hash-marked value. |
| 228 | preceding := b.buf[:len(b.buf)-m.EndLen] |
| 229 | startIdx := bytes.LastIndex(preceding, m.StartBytes) |
| 230 | isHashZone := startIdx >= 0 && |
| 231 | bytes.HasPrefix(preceding[startIdx+m.StartLen:], m.HashPrefixBytes) |
| 232 | if !isHashZone { |
| 233 | b.buf = preceding |
| 234 | b.markerOpen = true |
| 235 | return |
| 236 | } |
| 237 | } |
| 238 | p, ok := b.tryGrowByReslice(len(m.StartS)) |
| 239 | if !ok { |
| 240 | p = b.grow(len(m.StartS)) |
| 241 | } |
| 242 | copy(b.buf[p:], m.StartS) |
| 243 | b.markerOpen = true |
| 244 | } |
| 245 | |
| 246 | // escapeToEnd escapes occurrences of redaction markers in |
| 247 | // b.buf[b.validUntil:] and advances b.validUntil until the end. |
no test coverage detected