Skip to content

Commit

Permalink
Fix #60 Do not validate variable subsitutions in RUN
Browse files Browse the repository at this point in the history
The validator was primarily written to handle variable substitutions
in the Bash world but it seems like PowerShell does things quite
differently than Bash. Due to the wide range of differences that a
shell can choose to how to expand variables, the validator will simply
choose to skip RUN instructions over when validating variable
substitutions.

Signed-off-by: Remy Suen <[email protected]>
  • Loading branch information
rcjsuen committed May 22, 2019
1 parent 3948256 commit e6e4397
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file.
### Fixed
- allow quoted ARG variables in EXPOSE ([#58](https://github.com/rcjsuen/dockerfile-utils/issues/58))
- allow ENV variables that reference ARG variables in EXPOSE ([#57](https://github.com/rcjsuen/dockerfile-utils/issues/57))
- do not validate variable substitutions if found in RUN ([#60](https://github.com/rcjsuen/dockerfile-utils/issues/60))

## [0.0.12] - 2018-12-20
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion src/dockerValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class Validator {
for (let variable of instruction.getVariables()) {
let modifier = variable.getModifier();
if (modifier !== null) {
if (modifier === '?' && instruction.getKeyword() === Keyword.RUN) {
if (instruction.getKeyword() === Keyword.RUN) {
// allow shell expansions to go through for RUN instructions
continue;
} else if (modifier === "") {
Expand Down
26 changes: 22 additions & 4 deletions test/dockerValidator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1504,12 +1504,20 @@ describe("Docker Validator Tests", function() {

it("unsupported modifier", function() {
let diagnostics = validateDockerfile("FROM scratch\nENV bbb=123\n" + prefix + "${bbb:x}" + suffix);
assert.equal(diagnostics.length, 1);
assertVariableModifierUnsupported(diagnostics[0], "${bbb:x}", 'x', 2, length + 6, 2, length + 7);
if (prefix === "RUN ") {
assert.equal(diagnostics.length, 0);
} else {
assert.equal(diagnostics.length, 1);
assertVariableModifierUnsupported(diagnostics[0], "${bbb:x}", 'x', 2, length + 6, 2, length + 7);
}

diagnostics = validateDockerfile("FROM scratch\nENV bbb=123\n" + prefix + "${bbb:}" + suffix);
assert.equal(diagnostics.length, 1);
assertVariableModifierUnsupported(diagnostics[0], "${bbb:}", "", 2, length, 2, length + 7);
if (prefix === "RUN ") {
assert.equal(diagnostics.length, 0);
} else {
assert.equal(diagnostics.length, 1);
assertVariableModifierUnsupported(diagnostics[0], "${bbb:}", "", 2, length, 2, length + 7);
}
});

it("question mark modifier", function() {
Expand All @@ -1521,6 +1529,16 @@ describe("Docker Validator Tests", function() {
assertVariableModifierUnsupported(diagnostics[0], "${bbb:?}", '?', 2, length + 6, 2, length + 7);
}
});

it("no modifier", function() {
let diagnostics = validateDockerfile("FROM mcr.microsoft.com/windows/servercore:ltsc2019\nENV Env=123\n" + prefix + "${Env:TEMP}" + suffix);
if (prefix === "RUN ") {
assert.equal(diagnostics.length, 0);
} else {
assert.equal(diagnostics.length, 1);
assertVariableModifierUnsupported(diagnostics[0], "${Env:TEMP}", 'T', 2, length + 6, 2, length + 7);
}
});
}

describe("ADD", function() {
Expand Down

0 comments on commit e6e4397

Please sign in to comment.