`COPY`/`ADD` JSON form is rewritten to shell form even when paths contain spaces

Open Beginner friendly
#71 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
docker, go
Domain
devtools

Research direction

Start by locating the code that rewrites JSON-form COPY and ADD instructions, then check how it handles arguments containing whitespace. Use the reproduction Dockerfile in the issue to verify the formatter preserves the JSON form when paths contain spaces. Done means formatting no longer changes which source files or destinations the instructions name.

Written by the indexing model from the issue text.

Description

COPY and ADD in JSON (exec) form get rewritten to the space-separated form even when a path contains spaces. The JSON form exists for exactly that case, so the rewrite changes which files are copied and where.

Reproduce
FROM alpine
COPY ["my file.txt", "/app dir/"]
ADD ["src dir", "/opt/x y/"]
dockerfmt Dockerfile
Actual
FROM alpine
COPY my file.txt /app dir/
ADD src dir /opt/x y/

COPY my file.txt /app dir/ now names the sources my, file.txt and /app and the destination dir/. With a file called my file.txt in the context, the original builds and the output fails:

failed to compute cache key: failed to calculate checksum of ref ...: "/my": not found
Expected

Keep the JSON form when any argument contains whitespace, or don't convert COPY/ADD at all:

COPY ["my file.txt", "/app dir/"]
ADD ["src dir", "/opt/x y/"]

Reproduced with v0.5.4 and with main at a5868c2.

Dominant language
Go
Stars
626
Forks
23
Avg merge
6d 23h
Merged PRs (30d)
3

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from reteps/dockerfmt

All issues in reteps/dockerfmt

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.