Fix appendClassName to strip all trailing whitespace

This fixes the one failing test after the rewrite. It was failing because the old test did not properly test all conditions, while the rewritten one does. This pull request fixes the source code so the test passes.