Fix bug in here-doc parsing

When a here-doc contains an empty line, any whitespace it contains
should be ignored for purposes of determining the amount of leading
whitespace to trim from each line.
This commit is contained in:
Andrew Miner
2015-03-20 14:02:58 -07:00
parent 89a7f7a9d3
commit e58cc28815
2 changed files with 3 additions and 2 deletions
@@ -125,6 +125,7 @@ module.exports = class CommandParserVersionBase
shortestIndent = Number.MAX_VALUE
for hereDocLine in hereDocLines
continue if hereDocLine.trim().length is 0
shortestIndent = Math.min hereDocLine.match(/( *).*/)[1].length, shortestIndent
for i in [0...hereDocLines.length]
@@ -40,9 +40,9 @@ describe 'command_parser_version_base.coffee', ->
expect(result[1]).to.be.null
it 'trims smallest leading whitespace', ->
parser._lines = ['command: <<-END', ' alpha', ' bravo', ' charlie', 'END', 'command1: arg2']
parser._lines = ['command: <<-END', ' alpha', ' bravo', '', ' charlie', 'END', 'command1: arg2']
parser._lineNumber = 1
result = parser._parseHereDoc parser._lines[0]
result[0].should.equal 'command: '
result[1].should.equal 'alpha\n bravo\ncharlie'
result[1].should.equal 'alpha\n bravo\n\ncharlie'