Skip to content

util/sh: strip quotes when splitting build parameters - #412

Open
davidpavlovschi wants to merge 1 commit into
prometheus:masterfrom
davidpavlovschi:fix-split-quoted-parameters
Open

util/sh: strip quotes when splitting build parameters#412
davidpavlovschi wants to merge 1 commit into
prometheus:masterfrom
davidpavlovschi:fix-split-quoted-parameters

Conversation

@davidpavlovschi

Copy link
Copy Markdown

SplitParameters kept quoted sequences together but left the quotes in place, so a config with flags: -a -tags 'netgo static_build' passed the literal argument 'netgo static_build' to go build. Double quotes were not recognized at all, so -gcflags="all=-N -l" split into two arguments.

This replaces the regular expression with a small scanner that:

  • treats single and double quotes as grouping characters;
  • removes the surrounding quotes;
  • supports quotes within a parameter, including -gcflags="all=-N -l";
  • adds no dependency.

The table-driven tests cover the reported -tags case, the double-quoted equivalent, attached quotes, and whitespace handling.

Validation:

  • go test ./util/sh -run TestSplitParameters -count=1 -v
  • go test ./cmd/... ./pkg/... ./util/...
  • go vet ./...
  • make style
  • make unused
  • make lint

The full root-package test run also reaches two environment/pre-existing failures: the extldflags integration assertion reproduces on the clean base, and the crossbuild test requires Docker.

Fixes #172

@kakkoyun

Signed-off-by: David PAVLOVSCHII <david.pavlovschii@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parameter / flag parsing from YAML does not remove quotes around quoted arguments

1 participant