Skip to content

Commit 5230f20

Browse files
committed
filesync: escape special query characters
This ensures that files with '%' and '+' can still be properly copied. To prevent regressions, this also adds in a couple of example test cases. Signed-off-by: Justin Chadwell <[email protected]>
1 parent 31a9120 commit 5230f20

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

frontend/dockerfile/dockerfile_test.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6766,12 +6766,16 @@ func testCopyUnicodePath(t *testing.T, sb integration.Sandbox) {
67666766
dockerfile := []byte(`
67676767
FROM alpine
67686768
COPY test-äöü.txt /
6769+
COPY test-%C3%A4%C3%B6%C3%BC.txt /
6770+
COPY test+aou.txt /
67696771
`)
67706772

67716773
dir, err := integration.Tmpdir(
67726774
t,
67736775
fstest.CreateFile("Dockerfile", dockerfile, 0600),
6774-
fstest.CreateFile("test-äöü.txt", []byte("test"), 0644),
6776+
fstest.CreateFile("test-äöü.txt", []byte("foo"), 0644),
6777+
fstest.CreateFile("test-%C3%A4%C3%B6%C3%BC.txt", []byte("bar"), 0644),
6778+
fstest.CreateFile("test+aou.txt", []byte("baz"), 0644),
67756779
)
67766780
require.NoError(t, err)
67776781

@@ -6794,7 +6798,15 @@ COPY test-äöü.txt /
67946798

67956799
dt, err := os.ReadFile(filepath.Join(destDir, "test-äöü.txt"))
67966800
require.NoError(t, err)
6797-
require.Equal(t, "test", string(dt))
6801+
require.Equal(t, "foo", string(dt))
6802+
6803+
dt, err = os.ReadFile(filepath.Join(destDir, "test-%C3%A4%C3%B6%C3%BC.txt"))
6804+
require.NoError(t, err)
6805+
require.Equal(t, "bar", string(dt))
6806+
6807+
dt, err = os.ReadFile(filepath.Join(destDir, "test+aou.txt"))
6808+
require.NoError(t, err)
6809+
require.Equal(t, "baz", string(dt))
67986810
}
67996811

68006812
func runShell(dir string, cmds ...string) error {

session/filesync/filesync.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,9 @@ func decodeOpts(opts map[string][]string) map[string][]string {
387387
func encodeStringForHeader(input string) string {
388388
var output strings.Builder
389389
for _, runeVal := range input {
390-
// Only encode non-ASCII characters.
391-
if runeVal > unicode.MaxASCII {
390+
// Only encode non-ASCII characters, and characters that have special
391+
// meaning during decoding.
392+
if runeVal > unicode.MaxASCII || runeVal == '%' || runeVal == '+' {
392393
// Encode each non-ASCII character individually.
393394
output.WriteString(url.QueryEscape(string(runeVal)))
394395
} else {

0 commit comments

Comments
 (0)