diff --git a/src/instruction.ts b/src/instruction.ts index 2e4d40c..531c22b 100644 --- a/src/instruction.ts +++ b/src/instruction.ts @@ -652,7 +652,7 @@ export class Instruction extends Line { // instruction only on one line, if heredocs exist they would be incomplete for (const arg of args) { const value = arg.getValue(); - if (value.startsWith("<<")) { + if (value.startsWith("<<") && Util.parseHeredocName(value) !== null) { const startRange = arg.getRange(); const nameRange = this.getNameRange(startRange); const name = this.getName(nameRange); diff --git a/src/parser.ts b/src/parser.ts index dc2a97e..a6429a7 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -315,20 +315,6 @@ export class Parser { return this.buffer.length; } - private parseHeredocName(value: string): string | null { - value = value.substring(2); - if (value.charAt(0) === '-') { - value = value.substring(1); - } - if (value.charAt(0) === '"' || value.charAt(0) === '\'') { - value = value.substring(1, value.length - 1); - } - if (value.charAt(0) === "<") { - return null; - } - return value; - } - private processHeredocs(instruction: Instruction, offset: number): number { let keyword = instruction.getKeyword(); if (keyword === Keyword.ONBUILD) { @@ -345,7 +331,7 @@ export class Parser { for (const arg of instruction.getArguments()) { const value = arg.getValue(); if (value.startsWith("<<") && value.length > 2) { - const name = this.parseHeredocName(value); + const name = Util.parseHeredocName(value); if (name !== null) { heredocs.push(name); } diff --git a/src/util.ts b/src/util.ts index c3c0fc3..56195c0 100644 --- a/src/util.ts +++ b/src/util.ts @@ -71,4 +71,18 @@ export class Util { } return range.start.line < position.line && position.line < range.end.line; } + + public static parseHeredocName(value: string): string | null { + value = value.substring(2); + if (value.charAt(0) === '-') { + value = value.substring(1); + } + if (value.charAt(0) === '"' || value.charAt(0) === '\'') { + value = value.substring(1, value.length - 1); + } + if (value.charAt(0) === "<") { + return null; + } + return value; + } } diff --git a/test/heredoc.test.ts b/test/heredoc.test.ts index 297d40b..0226f06 100644 --- a/test/heredoc.test.ts +++ b/test/heredoc.test.ts @@ -417,6 +417,16 @@ describe("Heredoc", () => { assert.strictEqual(heredocs[0].getDelimiterRange(), null); }); + /** + * RUN << { + const instruction = DockerfileParser.parse(`${keyword} <<