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

ENVs and LABELs improperly parsed if they use variable replacement and is delimited with a = #24

Closed
rcjsuen opened this issue Apr 19, 2018 · 0 comments
Assignees
Labels

Comments

@rcjsuen
Copy link
Owner

rcjsuen commented Apr 19, 2018

The code below will produce the following output.

It seems that the parsing is fine if it is delimited by a space (which makes sense because the parser will just take everything after the space). Using a = will trigger the failure as it stops parsing the property after the second matching ' is found and proceeds to start reading the rest of the content as a new property.

2
${bundle_without:-'development test'
2
${bundle_without:-'development test'
1
${bundle_without:-'development test'}
1
${bundle_without:-'development test'}
import { DockerfileParser } from 'dockerfile-ast';

const content =
"FROM scratch\n" +
"ENV BUNDLE_WITHOUT=${bundle_without:-'development test'}\n" +
"LABEL BUNDLE_WITHOUT=${bundle_without:-'development test'}\n" +
"ENV BUNDLE_WITHOUT ${bundle_without:-'development test'}\n" +
"LABEL BUNDLE_WITHOUT ${bundle_without:-'development test'}\n";

let dockerfile = DockerfileParser.parse(content);
let env = dockerfile.getInstructions()[1] as Env;
let label = dockerfile.getInstructions()[2] as Label;
let env2 = dockerfile.getInstructions()[3] as Env;
let label2 = dockerfile.getInstructions()[4] as Label;

let property = env.getProperties()[0];
console.log(env.getProperties().length);
console.log(property.getValue());

property = label.getProperties()[0];
console.log(label.getProperties().length);
console.log(property.getValue());

property = env2.getProperties()[0];
console.log(env2.getProperties().length);
console.log(property.getValue());

property = label2.getProperties()[0];
console.log(label2.getProperties().length);
console.log(property.getValue());
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