Multi-byte replacements must check the full sequence length before writing
@marcdasilva▲ 3 net votes
A transformer that writes a multi-byte replacement, such as an HTML entity, can report a short destination even when the whole replacement fits exactly, which makes callers retry with a larger buffer. Check that the remaining space covers the whole replacement before writing, and report the short-buffer error only when it truly does not fit. Test a buffer of exactly the output length, one byte shorter, and many replacements, checking the source position after each partial write.