Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StringSlice trims leading and tailing spaces #1648

Closed
2 of 3 tasks
palsivertsen opened this issue Jan 16, 2023 · 1 comment
Closed
2 of 3 tasks

StringSlice trims leading and tailing spaces #1648

palsivertsen opened this issue Jan 16, 2023 · 1 comment
Labels
area/v2 relates to / is being considered for v2 kind/bug describes or fixes a bug status/triage maintainers still need to look into this

Comments

@palsivertsen
Copy link

My urfave/cli version is

v2.23.7

Checklist

  • Are you running the latest v2 release? The list of releases is here.
  • Did you check the manual for your release? The v2 manual is here <-- This link is broken.
  • Did you perform a search about this problem? Here's the GitHub guide about searching.

Dependency Management

  • My project is using go modules.

Describe the bug

I expect cli.StringSliceFlag to accept leading and tailing spaces, similar to the behavior of cli.StringFlag.

To reproduce

The following program (see Go Playground) shows that cli.StringSlice trims leading and tailing spaces in flag values.

package main

import (
	"fmt"
	"log"

	"github.com/urfave/cli/v2"
)

const expected = " <- spaces -> "

func main() {
	app := cli.App{
		Flags: []cli.Flag{
			&cli.StringFlag{Name: "string"},
			&cli.StringSliceFlag{Name: "slice"},
		},
		Action: func(ctx *cli.Context) error {
			s1, s2 := ctx.String("string"), ctx.StringSlice("slice")

			if len(s2) == 1 && s1 == s2[0] {
				return nil
			}

			_, err := fmt.Fprintf(ctx.App.Writer, "%q != %q", ctx.String("string"), ctx.StringSlice("slice")[0])
			return err
		},
	}

	if err := app.Run([]string{"", "--string", expected, "--slice", expected}); err != nil {
		log.Fatalf("app run: %s", err)
	}
}

Observed behavior

The value was trimmed of leading and tailing spaces.

Expected behavior

The value should be unchanged.

Additional context

Discovered while passing a regexp string as a flag value (^ ).

Want to fix this yourself?

Maybe

Run go version and paste its output here

go version go1.19.4 linux/amd64

Run go env and paste its output here

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/pal/.cache/go-build"
GOENV="/home/pal/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/pal/projects/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/pal/projects/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19.4"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/tmp/tmp.mbFOk4K7cf/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3921918458=/tmp/go-build -gno-record-gcc-switches"
@palsivertsen palsivertsen added area/v2 relates to / is being considered for v2 kind/bug describes or fixes a bug status/triage maintainers still need to look into this labels Jan 16, 2023
@skelouse
Copy link
Contributor

skelouse commented Jan 30, 2023

#1649

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/v2 relates to / is being considered for v2 kind/bug describes or fixes a bug status/triage maintainers still need to look into this
Projects
None yet
Development

No branches or pull requests

3 participants