Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 517525 - Dockerfile content assist parser should ignore invalid e…
…scape parser directive declarations

If the Dockerfile currently being edited defines an escape parser
directive that is not a backslash or a backtick or if it is not
defined correctly, the content assist parser should simply use the
original backslash character as the escape character.

This fallback behaviour brings the content assist parser in line with
the behaviour of the Dockerfile builder where an escape directive
that is not a backtick or a backslash will cause the builder to fail
and not build the Docker image. If on the other hand the escape
parser directive is properly declared but nothing follows the
declaration except a newline character, such declarations too will
also be ignored and the backslash character will be used as the
newline character instead.

Signed-off-by: Remy Suen <remy.suen@gmail.com>
  • Loading branch information
rcjsuen committed May 31, 2017
1 parent 5679de9 commit d009854
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
Expand Up @@ -708,7 +708,28 @@ define([
testEscape("", "VOLUME", "\\");
testEscape("", "WORKDIR", "\\");
});


it("#escape=\\n", function() {
testEscape("#escape=\n", "ADD", "\\");
testEscape("#escape=\n", "ARG", "\\");
testEscape("#escape=\n", "CMD", "\\");
testEscape("#escape=\n", "COPY", "\\");
testEscape("#escape=\n", "ENTRYPOINT", "\\");
testEscape("#escape=\n", "ENV", "\\");
testEscape("#escape=\n", "EXPOSE", "\\");
testEscape("#escape=\n", "FROM", "\\");
testEscape("#escape=\n", "HEALTHCHECK", "\\");
testEscape("#escape=\n", "LABEL", "\\");
testEscape("#escape=\n", "MAINTAINER", "\\");
testEscape("#escape=\n", "ONBUILD", "\\");
testEscape("#escape=\n", "RUN", "\\");
testEscape("#escape=\n", "SHELL", "\\");
testEscape("#escape=\n", "STOPSIGNAL", "\\");
testEscape("#escape=\n", "USER", "\\");
testEscape("#escape=\n", "VOLUME", "\\");
testEscape("#escape=\n", "WORKDIR", "\\");
});

it("#escape=`\\n", function() {
testEscape("#escape=`\n", "ADD", "`");
testEscape("#escape=`\n", "ARG", "`");
Expand Down Expand Up @@ -1107,6 +1128,15 @@ define([
testEscape("#\r\nescape=`", "VOLUME", "\\");
testEscape("#\r\nescape=`", "WORKDIR", "\\");
});

it("#escape=x", function() {
var content = "#escape=x\nFROM x\n";
var proposals = compute(content, content.length, {
prefix: "",
line: ""
});
assertAllProposals(proposals, content.length, "");
});
});
});

Expand Down
Expand Up @@ -61,9 +61,10 @@ define([
break;
default:
if (capture) {
// the escape directive should be a single character,
// so it should be followed by whitespace
if (j + 1 === buffer.length || isWhitespace(buffer.charAt(j + 1))) {
// the escape directive should be a single character and followed by whitespace,
// it should also either be a backslash or a backtick
if ((j + 1 === buffer.length || isWhitespace(buffer.charAt(j + 1)))
&& (char === '\\' || char === '`')) {
escapeCharacter = char;
}
break escapeCheck;
Expand Down

0 comments on commit d009854

Please sign in to comment.