Fix infinite loop on comment at end of file, add test.