From 01c14bc6402198b09f1a7f23f67e4ff05e8c562c Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 22 Sep 2010 08:47:43 -0500 Subject: [PATCH] Heredoc indentation detector ignores blank lines without trailing whitespace. --- lib/lexer.js | 2 +- src/lexer.coffee | 2 +- test/test_heredocs.coffee | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/lexer.js b/lib/lexer.js index 58d14678..2f453939 100644 --- a/lib/lexer.js +++ b/lib/lexer.js @@ -395,7 +395,7 @@ if (!(options.herecomment)) { while ((match = HEREDOC_INDENT.exec(doc)) !== null) { attempt = (typeof (_ref2 = match[2]) !== "undefined" && _ref2 !== null) ? match[2] : match[3]; - if (!(typeof indent !== "undefined" && indent !== null) || attempt.length < indent.length) { + if (!(typeof indent !== "undefined" && indent !== null) || (0 < attempt.length) && (attempt.length < indent.length)) { indent = attempt; } } diff --git a/src/lexer.coffee b/src/lexer.coffee index 0f6a12ba..cd2215a0 100644 --- a/src/lexer.coffee +++ b/src/lexer.coffee @@ -323,7 +323,7 @@ exports.Lexer = class Lexer unless options.herecomment while (match = HEREDOC_INDENT.exec(doc)) isnt null attempt = if match[2]? then match[2] else match[3] - indent = attempt if not indent? or attempt.length < indent.length + indent = attempt if not indent? or 0 < attempt.length < indent.length indent or= '' doc = doc.replace(new RegExp("^" + indent, 'gm'), '') return doc if options.herecomment diff --git a/test/test_heredocs.coffee b/test/test_heredocs.coffee index 55d9dc4d..8bf2ae98 100644 --- a/test/test_heredocs.coffee +++ b/test/test_heredocs.coffee @@ -79,3 +79,12 @@ ok b is "basic heredoc \#{val}\non two lines" a = '''here's an apostrophe''' ok a is "here's an apostrophe" + + +# The indentation detector ignores blank lines without trailing whitespace +a = """ + one + two + + """ +ok a is "one\ntwo\n"