Fix last_line_blank logic

The broken last_line_blank logic could lead to random failures in the
API tests.