From f9c5745c63fb6ae8342c689ea9a4c8c4dce14d4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20JACQUES?= Date: Tue, 12 Apr 2022 15:54:14 +0200 Subject: [PATCH] Fixes #2046: make target stage lookup case insensitive (#2047) --- pkg/dockerfile/dockerfile.go | 2 +- pkg/dockerfile/dockerfile_test.go | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/dockerfile/dockerfile.go b/pkg/dockerfile/dockerfile.go index 353185fee..3dd88cab3 100644 --- a/pkg/dockerfile/dockerfile.go +++ b/pkg/dockerfile/dockerfile.go @@ -197,7 +197,7 @@ func targetStage(stages []instructions.Stage, target string) (int, error) { return len(stages) - 1, nil } for i, stage := range stages { - if stage.Name == target { + if strings.EqualFold(stage.Name, target) { return i, nil } } diff --git a/pkg/dockerfile/dockerfile_test.go b/pkg/dockerfile/dockerfile_test.go index 64279c9e2..f61398689 100644 --- a/pkg/dockerfile/dockerfile_test.go +++ b/pkg/dockerfile/dockerfile_test.go @@ -261,6 +261,9 @@ func Test_targetStage(t *testing.T) { FROM scratch AS second COPY --from=0 /hi /hi2 + FROM scratch AS UPPER_CASE + COPY --from=0 /hi /hi2 + FROM scratch COPY --from=second /hi2 /hi3 ` @@ -280,10 +283,16 @@ func Test_targetStage(t *testing.T) { targetIndex: 1, shouldErr: false, }, + { + name: "test valid upper case target", + target: "UPPER_CASE", + targetIndex: 2, + shouldErr: false, + }, { name: "test no target", target: "", - targetIndex: 2, + targetIndex: 3, shouldErr: false, }, {