From f8ed81ad5af1a3568d1f16500fa0bb52d6924195 Mon Sep 17 00:00:00 2001 From: Ryan McGrath Date: Fri, 3 May 2013 16:18:16 -0400 Subject: [PATCH] Handles scenarios where lines might not end with a newline at the end of the file. Fixes #49. --- lib/wrench.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/wrench.js b/lib/wrench.js index 0139319..0b9b697 100644 --- a/lib/wrench.js +++ b/lib/wrench.js @@ -411,13 +411,13 @@ exports.LineReader.prototype = { if(this.currentPosition === -1) return false; } - if(this.buffer.indexOf("\n") > -1) return true; + if(this.buffer.indexOf("\n") > -1 || this.buffer.length !== 0) return true; return false; }, getNextLine: function() { var lineEnd = this.buffer.indexOf("\n"), - result = this.buffer.substring(0, lineEnd); + result = this.buffer.substring(0, lineEnd ? lineEnd : this.buffer.length); this.buffer = this.buffer.substring(result.length + 1, this.buffer.length); return result;