fix issue 8395

This is a PR to address #8395

I am not super happy about testing the nonWS again as is done below in the || comparison but I couldn't immediately think of a better way to do this.

As per the issue discussion, if the line has non-whitespace characters, the whitespace is not stripped.
I will give it a look.