Fix bug when trying to ignore a space in sorting

* Fix bug where a space at the end of any section was trimmed
  regardless of whether it was escaped.
* Add tests for ignoring spaces