Skip to content

fmt: Scanf rejects \r\n at end of line on Windows #51346

@msh2050

Description

@msh2050

What version of Go are you using (go version)?

$ go version
go1.17.7

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (v)?

windows 11 / amd64

go env Output
$ go env
set GO111MODULE=auto
set GOARCH=amd64
set GOBIN=
set GOCACHE=####\AppData\Local\go-build
set GOENV=####\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=####\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=####
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=###\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=####\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.17.7
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\msh20\AppData\Local\Temp\go-build1493363615=/tmp/go-build -gno-record-gcc-switches
same as in [this close issue](https://github.com//issues/5391)

What did you do?

package main

import (
    "fmt"
    "strconv"
)

func main() {

    for {
        name := ""
        fmt.Print("Enter : ")
        fmt.Scanf("%s", &name)
        b1, _ := strconv.ParseBool(name)
        fmt.Printf("%T, %v\n", b1, b1)
    }

}

this happens on vscode in windows 11 and Windows-terminal with (Powershell, cmd, and bash) and the same issue with cmder terminal. this will not happen with wsl and with MobaXterm terminal, I did not make further checking with other terminals.
I added question in stackoverflow before opening this issue

What did you expect to see?

Enter : true
bool, true 
Enter :

What did you see instead?

Enter : true
bool, true 
Enter : bool, false
Enter :

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions