@@ -565,24 +565,23 @@ func (s *StageExecutor) runStageMountPoints(mountList []string) (map[string]inte
565
565
stageMountPoints := make (map [string ]internal.StageMountDetails )
566
566
for _ , flag := range mountList {
567
567
if strings .Contains (flag , "from" ) {
568
- arr := strings .SplitN (flag , "," , 2 )
569
- if len (arr ) < 2 {
568
+ tokens := strings .Split (flag , "," )
569
+ if len (tokens ) < 2 {
570
570
return nil , fmt .Errorf ("Invalid --mount command: %s" , flag )
571
571
}
572
- tokens := strings .Split (flag , "," )
573
- for _ , val := range tokens {
574
- kv := strings .SplitN (val , "=" , 2 )
575
- switch kv [0 ] {
572
+ for _ , token := range tokens {
573
+ key , val , hasVal := strings .Cut (token , "=" )
574
+ switch key {
576
575
case "from" :
577
- if len ( kv ) == 1 {
576
+ if ! hasVal {
578
577
return nil , fmt .Errorf ("unable to resolve argument for `from=`: bad argument" )
579
578
}
580
- if kv [ 1 ] == "" {
579
+ if val == "" {
581
580
return nil , fmt .Errorf ("unable to resolve argument for `from=`: from points to an empty value" )
582
581
}
583
- from , fromErr := imagebuilder .ProcessWord (kv [ 1 ] , s .stage .Builder .Arguments ())
582
+ from , fromErr := imagebuilder .ProcessWord (val , s .stage .Builder .Arguments ())
584
583
if fromErr != nil {
585
- return nil , fmt .Errorf ("unable to resolve argument %q: %w" , kv [ 1 ] , fromErr )
584
+ return nil , fmt .Errorf ("unable to resolve argument %q: %w" , val , fromErr )
586
585
}
587
586
// If additional buildContext contains this
588
587
// give priority to that and break if additional
@@ -1748,9 +1747,9 @@ func (s *StageExecutor) getBuildArgsResolvedForRun() string {
1748
1747
dockerConfig := s .stage .Builder .Config ()
1749
1748
1750
1749
for _ , env := range dockerConfig .Env {
1751
- splitv := strings .SplitN (env , "=" , 2 )
1752
- if len ( splitv ) == 2 {
1753
- configuredEnvs [splitv [ 0 ]] = splitv [ 1 ]
1750
+ key , val , hasVal := strings .Cut (env , "=" )
1751
+ if hasVal {
1752
+ configuredEnvs [key ] = val
1754
1753
}
1755
1754
}
1756
1755
@@ -2102,8 +2101,8 @@ func (s *StageExecutor) commit(ctx context.Context, createdBy string, emptyLayer
2102
2101
s .builder .SetPort (string (p ))
2103
2102
}
2104
2103
for _ , envSpec := range config .Env {
2105
- spec := strings .SplitN (envSpec , "=" , 2 )
2106
- s .builder .SetEnv (spec [ 0 ], spec [ 1 ] )
2104
+ key , val , _ := strings .Cut (envSpec , "=" )
2105
+ s .builder .SetEnv (key , val )
2107
2106
}
2108
2107
for _ , envSpec := range s .executor .unsetEnvs {
2109
2108
s .builder .UnsetEnv (envSpec )
@@ -2139,12 +2138,8 @@ func (s *StageExecutor) commit(ctx context.Context, createdBy string, emptyLayer
2139
2138
// an intermediate image, in such case we must
2140
2139
// honor layer labels if they are configured.
2141
2140
for _ , labelString := range s .executor .layerLabels {
2142
- label := strings .SplitN (labelString , "=" , 2 )
2143
- if len (label ) > 1 {
2144
- s .builder .SetLabel (label [0 ], label [1 ])
2145
- } else {
2146
- s .builder .SetLabel (label [0 ], "" )
2147
- }
2141
+ labelk , labelv , _ := strings .Cut (labelString , "=" )
2142
+ s .builder .SetLabel (labelk , labelv )
2148
2143
}
2149
2144
}
2150
2145
for k , v := range config .Labels {
@@ -2157,12 +2152,8 @@ func (s *StageExecutor) commit(ctx context.Context, createdBy string, emptyLayer
2157
2152
s .builder .UnsetLabel (key )
2158
2153
}
2159
2154
for _ , annotationSpec := range s .executor .annotations {
2160
- annotation := strings .SplitN (annotationSpec , "=" , 2 )
2161
- if len (annotation ) > 1 {
2162
- s .builder .SetAnnotation (annotation [0 ], annotation [1 ])
2163
- } else {
2164
- s .builder .SetAnnotation (annotation [0 ], "" )
2165
- }
2155
+ annotationk , annotationv , _ := strings .Cut (annotationSpec , "=" )
2156
+ s .builder .SetAnnotation (annotationk , annotationv )
2166
2157
}
2167
2158
if imageRef != nil {
2168
2159
logName := transports .ImageName (imageRef )
0 commit comments