Test case for #163

Also cherry-pick fix made by @jesperp