Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiline instructions with embedded comments confuses Instruction's getArguments() #71

Closed
rcjsuen opened this issue Mar 7, 2020 · 1 comment
Assignees
Labels

Comments

@rcjsuen
Copy link
Owner

rcjsuen commented Mar 7, 2020

Given the Dockerfile below, the extra continuation newlines and comments should be ignored.

FROM alpine
RUN echo \
# comment

# comment
"Hello"
$ docker build .
Sending build context to Docker daemon  38.15MB
[WARNING]: Empty continuation line found in:
    RUN echo "Hello"
[WARNING]: Empty continuation lines will become errors in a future release.
Step 1/2 : FROM alpine
latest: Pulling from library/alpine
c9b1b535fdd9: Pull complete 
Digest: sha256:ab00606a42621fb68f2ed6ad3c88be54397f981a7b70a79db3d1172b11c4367d
Status: Downloaded newer image for alpine:latest
 ---> e7d92cdc71fe
Step 2/2 : RUN echo "Hello"
 ---> Running in 5a49db1abc9d
Hello
Removing intermediate container 5a49db1abc9d
 ---> 60a307c69178
Successfully built 60a307c69178

However, it appears to be confusing the parser and it thinks there are four arguments when there are only two.

import { DockerfileParser } from 'dockerfile-ast';
let content =
    "FROM alpine\n" +
    "RUN echo \\\n" +
    "# comment\n" +
    "\n" +
    "# comment\n" +
    "\"Hello\"";
let dockerfile = DockerfileParser.parse(
    content
);
let instruction = dockerfile.getInstructions()[1];
for (const a of instruction.getArguments()) {
    console.log(a);
}
Argument {
  value: 'echo',
  range:
   { start: { line: 1, character: 4 },
     end: { line: 1, character: 8 } } }
Argument {
  value: '#',
  range:
   { start: { line: 4, character: 0 },
     end: { line: 4, character: 1 } } }
Argument {
  value: 'comment',
  range:
   { start: { line: 4, character: 2 },
     end: { line: 4, character: 9 } } }
Argument {
  value: '"Hello"',
  range:
   { start: { line: 5, character: 0 },
     end: { line: 5, character: 7 } } }
@rcjsuen rcjsuen added the bug label Mar 7, 2020
@rcjsuen rcjsuen self-assigned this Mar 7, 2020
@rcjsuen
Copy link
Owner Author

rcjsuen commented Mar 7, 2020

From further testing, it looks like one comment is okay but multiple comments become a problem.

@rcjsuen rcjsuen closed this as completed in 6fcc611 Mar 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant