Skip to content

os: readConsole corrupts multibyte characters on Windows #17939

Closed
@mattn

Description

@mattn

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

go version devel +5af7553 Wed Nov 9 00:21:04 2016 +0000 windows/amd64

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

Windows 7 64bit

What did you do?

package main

import (
    "fmt"
    "os"
)

func main() {
    p := make([]byte, 100)
    fmt.Printf("> ")
    for {
        n, err := os.Stdin.Read(p)
        fmt.Printf("[%d %q %v]\n> ", n, p[:n], err)
    }
}

#17427 (comment)

go run and type hello\n on the prompt >.

What did you expect to see?

output [7 "hello\r\n" <nil>]

What did you see instead?

[1 "h" <nil>]
[1 "e" <nil>]
[1 "l" <nil>]
[1 "l" <nil>]
[1 "o" <nil>]
[1 "\r" <nil>]
[1 "\n" <nil>]

When 100 bytes buffer is given, readConsole should be filled with hello\r\n on console. Because GetConsoleMode() is ENABLE_LINE_INPUT and if call ReadFile with enough buffer, it fill as hello\r\n.

https://go-review.googlesource.com/#/c/31114/ will fix this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions