Issue #1327 regression test and fix

Hi Travis, I came up with a regression test and a fix, please merge or cherry-pick.

What's the impact of moving this line after 553?