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

cmd/go: detect UTF-16 encoded sources and improve error reporting #71872

Open
dolmen opened this issue Feb 21, 2025 · 2 comments
Open

cmd/go: detect UTF-16 encoded sources and improve error reporting #71872

dolmen opened this issue Feb 21, 2025 · 2 comments
Labels
FeatureRequest Issues asking for a new feature that does not need a proposal. GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. ToolProposal Issues describing a requested change to a Go tool or command-line program.
Milestone

Comments

@dolmen
Copy link
Contributor

dolmen commented Feb 21, 2025

Go version

go version go1.24.0 windows/amd64

Output of go env in your module/workspace:

set GOOS=windows

What did you do?

A text file created with the echo command in PowerShell on Windows 11 is encoded in UTF-16.

Windows PowerShell
Copyright (C) Microsoft Corporation. Tous droits réservés.

Installez la dernière version de PowerShell pour de nouvelles fonctionnalités et améliorations ! https://aka.ms/PSWindows

PS C:\Users\dolmen> cd Code
PS C:\Users\dolmen\Code> mkdir hello


    Répertoire : C:\Users\dolmen\Code


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        21/02/2025     13:46                hello


PS C:\Users\dolmen\Code> cd hello
PS C:\Users\dolmen\Code\hello> go mod init github.com/dolmen-go/hello
go: creating new go.mod: module github.com/dolmen-go/hello
PS C:\Users\dolmen\Code\hello> echo "package main" > hello.go
PS C:\Users\dolmen\Code\hello> type hello.go
package main
PS C:\Users\dolmen\Code\hello> go build .
read C:\Users\dolmen\Code\hello\hello.go: unexpected NUL in input
PS C:\Users\dolmen\Code\hello> Format-Hex hello.go


           Chemin d'accès : C:\Users\dolmen\Code\hello\hello.go

           00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F

00000000   FF FE 70 00 61 00 63 00 6B 00 61 00 67 00 65 00  .þp.a.c.k.a.g.e.
00000010   20 00 6D 00 61 00 69 00 6E 00 0D 00 0A 00         .m.a.i.n.....


PS C:\Users\dolmen\Code\hello> go fmt .
read C:\Users\dolmen\Code\hello\hello.go: unexpected NUL in input

What did you see happen?

PS C:\Users\dolmen\Code\hello> go build .
read C:\Users\dolmen\Code\hello\hello.go: unexpected NUL in input
PS C:\Users\dolmen\Code\hello> go fmt .
read C:\Users\dolmen\Code\hello\hello.go: unexpected NUL in input

What did you expect to see?

The Go parser should detect that the NUL byte in the file is due to the file being encoded as UTF-16 (the NUL byte detection should trigger a check of the BOM) and report a specific message about an encoding issue.

This is an usability issue because some popular text editors such as Visual Studio Code do not (yet) signal the incorrect encoding.

@gabyhelp
Copy link

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

@gabyhelp gabyhelp added the ToolProposal Issues describing a requested change to a Go tool or command-line program. label Feb 21, 2025
@mknyszek mknyszek added the GoCommand cmd/go label Feb 21, 2025
@mknyszek mknyszek added this to the Backlog milestone Feb 21, 2025
@mknyszek mknyszek added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. and removed GoCommand cmd/go labels Feb 21, 2025
@mknyszek
Copy link
Contributor

CC @golang/compiler and maybe @matloob for the Go command?

@mknyszek mknyszek added the FeatureRequest Issues asking for a new feature that does not need a proposal. label Feb 21, 2025
@seankhliao seankhliao added the GoCommand cmd/go label Feb 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest Issues asking for a new feature that does not need a proposal. GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. ToolProposal Issues describing a requested change to a Go tool or command-line program.
Projects
None yet
Development

No branches or pull requests

4 participants