diff --git a/frontend/dockerfile/dockerfile_test.go b/frontend/dockerfile/dockerfile_test.go index 640415aa426e..c12a4e174e5a 100644 --- a/frontend/dockerfile/dockerfile_test.go +++ b/frontend/dockerfile/dockerfile_test.go @@ -155,6 +155,7 @@ var allTests = integration.TestFuncs( testNamedMultiplatformInputContext, testNamedFilteredContext, testEmptyDestDir, + testPreserveDestDirSlash, testCopyLinkDotDestDir, testCopyLinkEmptyDestDir, testCopyChownCreateDest, @@ -550,6 +551,42 @@ RUN cmd /V:on /C "set /p tfcontent= 1 && hasTrailingSlash { + return cleanedPath + string(filepath.Separator) + } + return cleanedPath } diff --git a/util/system/path_test.go b/util/system/path_test.go index c8d97c72d5ed..da0788aa185f 100644 --- a/util/system/path_test.go +++ b/util/system/path_test.go @@ -163,6 +163,23 @@ func TestCheckSystemDriveAndRemoveDriveLetter(t *testing.T) { if _, err = CheckSystemDriveAndRemoveDriveLetter(`\\.\C$\test`, "windows"); err == nil { t.Fatalf("UNC path should fail") } + + if path, err = CheckSystemDriveAndRemoveDriveLetter("\\a\\b\\..\\c\\", "windows"); err != nil { + t.Fatalf("windows relative paths should be cleaned and should pass") + } + // When input OS is Windows, the path should be properly cleaned + if path != "/a/c/" { + t.Fatalf("Path was not cleaned successfully") + } + + // windows-style relative paths on linux + if path, err = CheckSystemDriveAndRemoveDriveLetter("\\a\\b\\..\\c\\", "linux"); err != nil { + t.Fatalf("windows style relative paths should be considered a valid path element in linux and should pass") + } + // When input OS is Linux, this is a valid path element name. + if path != "\\a\\b\\..\\c\\" { + t.Fatalf("Path was not cleaned successfully") + } } // TestNormalizeWorkdir tests NormalizeWorkdir