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

Dockerfile: fix parsing of trailing backslash #1559

Merged
merged 2 commits into from
Oct 29, 2020

Conversation

thaJeztah
Copy link
Member

fixes docker/for-win#5254

If the line-continuation marker (\) is escaped, it should not be treated as such, but as a literal backslash, for example, the following should produce 5 ENV instructions:

FROM hello-world

ENV A path
ENV B another\\path
ENV C trailing\\backslash\\
ENV D This gets appended to C
ENV E hello\
\
world

@thaJeztah
Copy link
Member Author

@tiborvass @tonistiigi @AkihiroSuda ptal

@tonistiigi
Copy link
Member

Isn't this why

# escape=`

was added?

@thaJeztah
Copy link
Member Author

While

# escape=`

Would help not having to escape backslashes, and help with PowerShell scripts (which, I think was the main purpose), I think it would still need to handle escaped line-continuation markers at the end (e.g. an env-var with a trailing ``` should also be possible, correct?)

@tonistiigi tonistiigi added this to the v0.8.0 milestone Jul 21, 2020
ENV A path
ENV B another\\path
ENV C trailing\\backslash\\
ENV D This gets appended to C
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thaJeztah this is a bit confusing as the text says it gets appended to C, but it doesn't and it shouldn't, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good one, yes, I copied the "reproducer" example, but I guess it would be better to change to "This should not be appended to C" in the test

return errors.Errorf("invalid escape token '%s' does not match ` or \\", s)
}
d.escapeToken = rune(s[0])
d.lineContinuationRegex = regexp.MustCompile(`\` + s + `[ \t]*$`)
d.lineContinuationRegex = regexp.MustCompile(`([^\` + s + `])\` + s + `[ \t]*$|^\` + s + `[ \t]*$`)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't using optional block suffice?

regexp.MustCompile(`([^\` + s + `])?\` + s + `[ \t]*$`)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will have to give that a test 🤔 it's been a while since I wrote this 😂

Copy link
Member Author

@thaJeztah thaJeztah Oct 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I recall why it was needed; the second branch is needed for line-continuation symbols on their own line, which would otherwise be handled incorrectly.

Let me add some additional comments to this block, as there's also one corner-case we can't match easily (line-continuation preceded by an escaped escape-token, e.g.;

RUN echo hello\\\
world

Which should result in echo hello\\world, but we currently don't match

@tonistiigi
Copy link
Member

ping @thaJeztah if you want to get this in v0.8

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
If the line-continuation marker (`\`) is escaped, it should not be
treated as such, but as a literal backslash.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah
Copy link
Member Author

@tiborvass @tonistiigi updated; PTAL

@tiborvass tiborvass merged commit 6b1c950 into moby:master Oct 29, 2020
@thaJeztah thaJeztah deleted the fix_trailing_escape branch October 29, 2020 07:58
tiborvass pushed a commit to tiborvass/docker that referenced this pull request Nov 14, 2020
This old test is failing after an edge-case change in dockerfile
parsing considered a bugfix: moby/buildkit#1559

Instead of fixing the test, I suggest removing it as there are already
tests for it in BuildKit.

Signed-off-by: Tibor Vass <tibor@docker.com>
docker-jenkins pushed a commit to docker-archive/docker-ce that referenced this pull request Nov 17, 2020
This old test is failing after an edge-case change in dockerfile
parsing considered a bugfix: moby/buildkit#1559

Instead of fixing the test, I suggest removing it as there are already
tests for it in BuildKit.

Signed-off-by: Tibor Vass <tibor@docker.com>
Upstream-commit: beff0a5f2c62e655260c09697680c25a3e9a7ce1
Component: engine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

docker mishandles trailing backslashes in ENV if backslash is the escape character.
3 participants