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:
@@ -125,6 +125,7 @@ module.exports = class CommandParserVersionBase
|
|||||||
|
|
||||||
shortestIndent = Number.MAX_VALUE
|
shortestIndent = Number.MAX_VALUE
|
||||||
for hereDocLine in hereDocLines
|
for hereDocLine in hereDocLines
|
||||||
|
continue if hereDocLine.trim().length is 0
|
||||||
shortestIndent = Math.min hereDocLine.match(/( *).*/)[1].length, shortestIndent
|
shortestIndent = Math.min hereDocLine.match(/( *).*/)[1].length, shortestIndent
|
||||||
|
|
||||||
for i in [0...hereDocLines.length]
|
for i in [0...hereDocLines.length]
|
||||||
|
|||||||
@@ -40,9 +40,9 @@ describe 'command_parser_version_base.coffee', ->
|
|||||||
expect(result[1]).to.be.null
|
expect(result[1]).to.be.null
|
||||||
|
|
||||||
it 'trims smallest leading whitespace', ->
|
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
|
parser._lineNumber = 1
|
||||||
|
|
||||||
result = parser._parseHereDoc parser._lines[0]
|
result = parser._parseHereDoc parser._lines[0]
|
||||||
result[0].should.equal 'command: '
|
result[0].should.equal 'command: '
|
||||||
result[1].should.equal 'alpha\n bravo\ncharlie'
|
result[1].should.equal 'alpha\n bravo\n\ncharlie'
|
||||||
|
|||||||
Reference in New Issue
Block a user