-
Notifications
You must be signed in to change notification settings - Fork 18k
x/mod/modfile: parser includes newlines in comment text #39913
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
Comments
CC @jayconrod |
It looks like this is a regression in This doesn't seem like a Windows-specific issue, though it might have been in |
This means the source locations and lengths for comments will be the same on Windows and Unix-like platforms. Note this works around golang/go#39913
Change https://golang.org/cl/240557 mentions this issue: |
Thanks @jayconrod! |
In v0.2.0, the go.mod lexer removed trailing LF bytes from comment tokens. This regressed in v0.3.0. Documentation on Comment.Token says the trailing newline should not be included. This CL fixes the lexer to strip trailing newlines again. It will now strip both LF and CRLF newlines. It also includes a test to ensure comments are attached at the right place in the syntax tree with the right content. Fixes golang/go#39913 Change-Id: I7fba0ed3c85f0a3c23fefc6b7fecfe6df7777aea Reviewed-on: https://go-review.googlesource.com/c/mod/+/240557 Run-TryBot: Jay Conrod <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Michael Matloob <[email protected]>
NB. this is probably the wrong issue tracker;
github.com/golang/mod
describes itself as a[mirror]
but doesn't say what it's mirroring or where to contact the real maintainers, and googling doesn't reveal any obvious primary repo, so if that's the case please let me know where to refile and/or add a note to the mirror repo's descriptionWhat version of Go are you using (
go version
)?1.14
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?Don't currently have access to that box, but a generic Win32 Github Actions VM
What did you do?
Parse a go.mod file including comments using
golang.org/x/mod/modfile
What did you expect to see?
Comments should not include newline characters
What did you see instead?
On Win32, the
\r
of the CRLF line-ending is included in the comment'sToken
field.\r
characters are mostly skipped (https://github.com/golang/mod/blob/master/modfile/read.go#L504) but the code to specifically find the end of a comment (https://github.com/golang/mod/blob/master/modfile/read.go#L522) does not account for a CRLF line-ending. That could be a deliberate choice (the documentation makes no claim either way), but it doesn't seem likely.The text was updated successfully, but these errors were encountered: