RUBY-15071: restoring an old logic which fights with extra new-lines
reviewed by Sergey Simonchik
(cherry picked from commit 4a1dd3b)