Possible fix for #538

I still need to write tests for this case to ensure I didn't break anything else, but the case described in issue #538 is fixed by this.
It looks like my editor decided do change some whitespace, probably deleting trailing ones. Is this ok?