Add regression test for encoding behavior.

Broken in fc97ecd5bbb7c02a796e6852078292d020c2d0af.