This problem exist also with lines finished by an entity or a smiley and spaces (not just one) in the last caracters.
Test case (wiki syntax)
I have done a test cases page
http://www.dokuwiki.org/list_tests (sorry if its not at the right place).
The patch provided in the previous post seems to work on each cases (i haven't tested with tabs)
I add this comment and test case to help find the right solution, the impact on my wiki is more than just for new lines.