Skip to content

Commit

Permalink
Fix #112 Ignore empty continuation lines in heredocs in COPY instruct…
Browse files Browse the repository at this point in the history
…ions

Signed-off-by: Remy Suen <[email protected]>
  • Loading branch information
rcjsuen committed Aug 23, 2022
1 parent d4f4c1c commit bddf8cf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.
## [Unreleased]
### Added
- update formatter to ignore heredocs embedded in COPY instructions ([#111](https://github.com/rcjsuen/dockerfile-utils/issues/111))
- ignore empty continuation lines in heredocs embedded in COPY instructions ([#112](https://github.com/rcjsuen/dockerfile-utils/issues/112))

### Fixed
- ignore UTF-8 BOM when validating the Dockerfile ([#113](https://github.com/rcjsuen/dockerfile-utils/issues/113))
Expand Down
2 changes: 1 addition & 1 deletion src/dockerValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ export class Validator {
* here-documents are defined
*/
private getHeredocLines(instruction: Instruction): number[] {
if (instruction instanceof Run) {
if (instruction instanceof Copy || instruction instanceof Run) {
const lines: number[] = [];
for (const heredoc of instruction.getHeredocs()) {
const range = heredoc.getContentRange();
Expand Down
38 changes: 22 additions & 16 deletions test/dockerValidator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
import * as assert from "assert";
import { Keyword } from "dockerfile-ast";

import { TextDocument } from 'vscode-languageserver-textdocument';
import { Diagnostic, DiagnosticSeverity, DiagnosticTag } from 'vscode-languageserver-types';
Expand Down Expand Up @@ -1625,25 +1626,30 @@ describe("Docker Validator Tests", function() {
});

describe("heredocs", () => {
it("single, no content at all", () => {
const diagnostics = validateDockerfile("FROM alpine\nRUN <<eot file.txt\n\neot", { emptyContinuationLine: ValidationSeverity.WARNING });
assert.strictEqual(diagnostics.length, 0);
});
function testHeredocs(instruction: string): void {
it("single, no content at all", () => {
const diagnostics = validateDockerfile(`FROM alpine\n${instruction} <<eot file.txt\n\neot`, { emptyContinuationLine: ValidationSeverity.WARNING });
assert.strictEqual(diagnostics.length, 0);
});

it("single, has some content", () => {
const diagnostics = validateDockerfile("FROM alpine\nRUN <<eot file.txt\nabc\n\neot", { emptyContinuationLine: ValidationSeverity.WARNING });
assert.strictEqual(diagnostics.length, 0);
});
it("single, has some content", () => {
const diagnostics = validateDockerfile(`FROM alpine\n${instruction} <<eot file.txt\nabc\n\neot`, { emptyContinuationLine: ValidationSeverity.WARNING });
assert.strictEqual(diagnostics.length, 0);
});

it("multiple, no content at all", () => {
const diagnostics = validateDockerfile("FROM alpine\nRUN <<eot file.txt <<eot2 file2.txt\n\neot\n\neot2", { emptyContinuationLine: ValidationSeverity.WARNING });
assert.strictEqual(diagnostics.length, 0);
});
it("multiple, no content at all", () => {
const diagnostics = validateDockerfile(`FROM alpine\n${instruction} <<eot file.txt <<eot2 file2.txt\n\neot\n\neot2`, { emptyContinuationLine: ValidationSeverity.WARNING });
assert.strictEqual(diagnostics.length, 0);
});

it("multiple, has some content", () => {
const diagnostics = validateDockerfile("FROM alpine\nRUN <<eot file.txt <<eot2 file2.txt\nabc\n\neot\nabc\n\neot2", { emptyContinuationLine: ValidationSeverity.WARNING });
assert.strictEqual(diagnostics.length, 0);
});
it("multiple, has some content", () => {
const diagnostics = validateDockerfile(`FROM alpine\n${instruction} <<eot file.txt <<eot2 file2.txt\nabc\n\neot\nabc\n\neot2`, { emptyContinuationLine: ValidationSeverity.WARNING });
assert.strictEqual(diagnostics.length, 0);
});
}

testHeredocs(Keyword.COPY);
testHeredocs(Keyword.RUN);
});
});
});
Expand Down

0 comments on commit bddf8cf

Please sign in to comment.