I had a curious bug appear in my server logs when using a unicode Transformer:
transform unicode "wind-Pa\x00\x00\x00" to ascii: transform: short destination buffer
Here's the simplified code that caused the error (
Gist and
Go Playground). I assumed that converting from unicode to ascii would always have an equal or smaller length, hence the panic. Here's the essential bits of the simplified code:
cs := []byte("wind-Pa\x00\x00\x00")
chars := make([]byte, len(cs))
t := transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), norm.NFC)
nDst, _, err := t.Transform(chars, cs, true)
I suspect the error is thrown by
text/runes.go:149 (or perhaps on line 165) by the remove transformer. It looks like the form transformers never throw ErrShortDestination.
I haven't been able to reproduce the error on my dev mac or on the playground and there's only been a single occurrence of the error in my server logs. The server binary was compiled with Bazel for the @io_bazel_rules_go//go/toolchain:linux_amd64 toolchain using Go version 1.18.4.
I'd like to understand when ErrShortDestination is thrown by the Transformer. My code allocates a buffer the same length as the input so I thought I'd avoid the short destination error.