Skip to content

Commit b50f059

Browse files
dustinspeckerEric Stroczynski
authored and
Eric Stroczynski
committed
cmd/operator-sdk/build: fix handling of spaces within quotes (#2312)
Before when running `operator-sdk build` with an `--image-build-arg` of something like `--label some.name="First Last"` then `operator-sdk` would invoke the builder with ["--label", "some.name=First", "Last"], when it was actually desired to be ["--label", "some.name=First Last"]. Using `shlex` handles all the appropriate parsing of spaces within quotes unlike `strings.Fields` which just splits on any spaces regardless of context like quotes. Switching to `shlex` enables `operator-sdk build` to now properly handle spaces within quotes.
1 parent 3af79ea commit b50f059

File tree

6 files changed

+13
-1
lines changed

6 files changed

+13
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717

1818
### Bug Fixes
19+
- Fix `operator-sdk build`'s `--image-build-args` to support spaces within quotes like `--label some.name="First Last"`. ([#2312](https://github.com/operator-framework/operator-sdk/pull/2312))
1920

2021

2122
## v0.13.0

cmd/operator-sdk/build/cmd.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/operator-framework/operator-sdk/internal/scaffold"
2626
"github.com/operator-framework/operator-sdk/internal/util/projutil"
2727

28+
"github.com/google/shlex"
2829
log "github.com/sirupsen/logrus"
2930
"github.com/spf13/cobra"
3031
)
@@ -73,7 +74,10 @@ func createBuildCommand(imageBuilder, context, dockerFile, image string, imageBu
7374

7475
for _, bargs := range imageBuildArgs {
7576
if bargs != "" {
76-
splitArgs := strings.Fields(bargs)
77+
splitArgs, err := shlex.Split(bargs)
78+
if err != nil {
79+
return nil, fmt.Errorf("image-build-args is not parseable: %w", err)
80+
}
7781
args = append(args, splitArgs...)
7882
}
7983
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ require (
1616
github.com/go-logr/zapr v0.1.1
1717
github.com/gobuffalo/packr v1.30.1 // indirect
1818
github.com/gobwas/glob v0.2.3 // indirect
19+
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
1920
github.com/gregjones/httpcache v0.0.0-20190203031600-7a902570cb17 // indirect
2021
github.com/huandu/xstrings v1.2.0 // indirect
2122
github.com/iancoleman/strcase v0.0.0-20190422225806-e506e3ef7365

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,8 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/
320320
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
321321
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
322322
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
323+
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
324+
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
323325
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
324326
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
325327
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=

hack/tests/subcommand.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ if [ -z "$KUBECONFIG" ]; then
88
fi
99

1010
pushd test/test-framework
11+
# test building image with image-build-args having a space within quotes
12+
operator-sdk build operator-sdk-dev --image-build-args="--label some.name=\"First Last\""
13+
1114
# test framework with defaults
1215
operator-sdk test local ./test/e2e
1316

test/test-framework/go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/
281281
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
282282
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
283283
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
284+
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
284285
github.com/google/uuid v1.0.0 h1:b4Gk+7WdP/d3HZH8EJsZpvV7EtDOgaZLtnaNGIu1adA=
285286
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
286287
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=

0 commit comments

Comments
 (0)