mirror of
https://github.com/golang/go
synced 2024-11-17 20:04:47 -07:00
go/build: skip string literal while findEmbed
The findEmbed function looking for comment by readbyte, however it might have constant or variables that contains comment. Maybe we should use ast parser in the future. Fixes #43373 Change-Id: I92544384fc4c11363d8b2f6b9898c8dea1602767 Reviewed-on: https://go-review.googlesource.com/c/go/+/280332 Trust: Matthew Dempsky <mdempsky@google.com> Trust: Meng Zhuo <mzh@golangcn.org> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
parent
d92f8add32
commit
a9ccd2d795
@ -171,6 +171,41 @@ func (r *importReader) findEmbed(first bool) bool {
|
||||
case ' ', '\t':
|
||||
// leave startLine alone
|
||||
|
||||
case '"':
|
||||
startLine = false
|
||||
for r.err == nil {
|
||||
if r.eof {
|
||||
r.syntaxError()
|
||||
}
|
||||
c = r.readByteNoBuf()
|
||||
if c == '\\' {
|
||||
r.readByteNoBuf()
|
||||
if r.err != nil {
|
||||
r.syntaxError()
|
||||
return false
|
||||
}
|
||||
continue
|
||||
}
|
||||
if c == '"' {
|
||||
c = r.readByteNoBuf()
|
||||
goto Reswitch
|
||||
}
|
||||
}
|
||||
goto Reswitch
|
||||
|
||||
case '`':
|
||||
startLine = false
|
||||
for r.err == nil {
|
||||
if r.eof {
|
||||
r.syntaxError()
|
||||
}
|
||||
c = r.readByteNoBuf()
|
||||
if c == '`' {
|
||||
c = r.readByteNoBuf()
|
||||
goto Reswitch
|
||||
}
|
||||
}
|
||||
|
||||
case '/':
|
||||
c = r.readByteNoBuf()
|
||||
switch c {
|
||||
|
@ -255,6 +255,26 @@ var readEmbedTests = []struct {
|
||||
"package p\nimport \"embed\"\n//go:embed x y z\nvar files embed.FS",
|
||||
[]string{"x", "y", "z"},
|
||||
},
|
||||
{
|
||||
"package p\nimport \"embed\"\nvar s = \"/*\"\n//go:embed x\nvar files embed.FS",
|
||||
[]string{"x"},
|
||||
},
|
||||
{
|
||||
`package p
|
||||
import "embed"
|
||||
var s = "\"\\\\"
|
||||
//go:embed x
|
||||
var files embed.FS`,
|
||||
[]string{"x"},
|
||||
},
|
||||
{
|
||||
"package p\nimport \"embed\"\nvar s = `/*`\n//go:embed x\nvar files embed.FS",
|
||||
[]string{"x"},
|
||||
},
|
||||
{
|
||||
"package p\nimport \"embed\"\nvar s = z/ *y\n//go:embed pointer\nvar pointer embed.FS",
|
||||
[]string{"pointer"},
|
||||
},
|
||||
{
|
||||
"package p\n//go:embed x y z\n", // no import, no scan
|
||||
nil,
|
||||
|
Loading…
Reference in New Issue
Block a user