-
Notifications
You must be signed in to change notification settings - Fork 15
Fix name/val parsing when value is quoted #3
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
base: master
Are you sure you want to change the base?
Conversation
Thanks for the patch. Whilst this successfully removes the double-quotes, I have some dependent components that rely on the quoting being preserved (or rather the quoting is later parsed/removed in a separate component). I'm wondering if you could make this an optional feature, by setting an option (e.g. |
Just curious, why rely on the quotes being there? That's not how Dockerfiles are parsed officially as far as I can tell. If you need quotes on the values, why not do |
The quotes are used by the docker server, to display build output back to the client: Here is an example: $ cat Dockerfile
FROM busybox
LABEL this="cool beans"
LABEL this="cool \" quoted beans"
LABEL foo=bar bar="baz" "baz=dil"
$ docker build .
Sending build context to Docker daemon 632.3kB
Step 1/4 : FROM busybox
---> c30178c5239f
Step 2/4 : LABEL this "cool beans"
---> Running in f086ef9ff5e3
---> 543be5d49273
Removing intermediate container f086ef9ff5e3
Step 3/4 : LABEL this "cool \" quoted beans"
---> Running in d568e10c7b32
---> 58c974d6cbfb
Removing intermediate container d568e10c7b32
Step 4/4 : LABEL foo bar bar "baz" "baz dil"
---> Running in ebe6b5377930
---> 24da41c2a3e2
Removing intermediate container ebe6b5377930
Successfully built 24da41c2a3e2 As you can see from the Step output above, it's not exactly as simple as wrapping with quotes, as docker is preserving the original Dockerfile quotation. |
Sure, but I believe they're parsing those files much differently than what this module is intended for, no? The goal of this module is to extract the relevant values, correct? Quotes make no sense in the parsed data. That's like if your shell retained the quotes on the command line. $ ./my-program "foo" "bar baz" \"hello\" Which currently get parsed as:
It would be catastrophic if the following were true: int main(int, const char **argv) {
bool isFoo = string(argv[1]) == "foo"; // false! argv[1] is "\"foo\""
} I strongly believe Docker is merely echoing out the lines it parses as it parses them. I know Docker parses/processes line by line since interrupting or killing a build makes Docker think it's completed up to a certain part in the Docker file. I think the fact Docker naïvely parses its Dockerfiles allows it to simply echo out the raw text that was in the Dockerfile (though I'm speculating). Regardless, quotes in Dockerfiles are merely for syntax, not for semantics. I think keeping them in the parsed input significantly reduces the parser's usefulness and causes a lot of guesswork for downstream dependents. |
This code is a direct translation from the docker code: The same happens for the dependent components I mentioned (that rely on the quotes being there), in the same way as docker's shell parser above: The docker server is not just echoing a raw representation of the text, as shown in this example:
for which docker will echo (intermediate whitespace is removed, quotes are preserved, equal sign was replaced with a space):
Now I need to keep the same behaviour to docker, as the components that depend on this act as a real docker server, so they must output the same format/information. |
ref vercel/vercel#682
One of our users reported that their
LABEL
command was being incorrectly parsed. It appears quoted values in name/value pairs don't have their quotes removed when being parsed (although it does appear the quoted are being honored).This PR fixes that by stripping the quotes from the beginning and end if they exist.