Skip to content

Command Line Parameters with double quotation marks are not parsed properly by C runtime library used on windows platform by GO, ["TestPassword"] results in [TestPassword]. Quotes filtered out, no escape possible. #69057

Closed as not planned
@SkybuckFlying

Description

@SkybuckFlying

Go version

go version go1.22.2 windows/amd64

Output of go env in your module/workspace:

Microsoft Windows [Version 10.0.22631.4037]
(c) Microsoft Corporation. All rights reserved.

V:\Go\Tests\test show command line parameters\version 0.02 add c debugging>go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\skybu\AppData\Local\go-build
set GOENV=C:\Users\skybu\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=v:\gopath\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=v:\gopath
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=G:\Tools\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=G:\Tools\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.22.2
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set GOMOD=V:\Go\Tests\test show command line parameters\version 0.02 add c debugging\go.mod
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=G:\Temp\go-build1046575745=/tmp/go-build -gno-record-gcc-switches

V:\Go\Tests\test show command line parameters\version 0.02 add c debugging>

What did you do?

Trying to pass: ["TestPassword"]

Tried all kinds of escape characters. " " Simply gets filtered out resulting in wrong input: [TestPassword]

package main

import (
	"fmt"
	"os"
	"runtime/debug"
)

func main() {
	if len(os.Args) > 1 {
		fmt.Println("Command line arguments:")

		// Store each argument in a separate variable inside the loop
		for i, arg := range os.Args[1:] {
			// Store the current argument in a variable for debugging
			currentArg := arg

			// Print the stored variable for debugging
			fmt.Printf("Argument %d: %s\n", i+1, currentArg)
		}
	} else {
		fmt.Println("No command line arguments provided.")
	}
}

What did you see happen?

Wrong input: [TestPassword]

What did you expect to see?

["TestPassword"]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions