зеркало из https://github.com/golang/tools.git
txtar/archive: ignore invalid file separators
In case the file separator line does not define a filename, it should be ignored. Updates golang/go#47193 Change-Id: I3a0fee584c0f6b2b41814e79d20884d6468a3b76 Reviewed-on: https://go-review.googlesource.com/c/tools/+/336932 Run-TryBot: Jay Conrod <jayconrod@google.com> gopls-CI: kokoro <noreply+kokoro@google.com> Reviewed-by: Jay Conrod <jayconrod@google.com> Trust: Jay Conrod <jayconrod@google.com> Trust: Michael Matloob <matloob@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
Родитель
4fe0d6c80e
Коммит
ebce39e5e3
|
@ -121,7 +121,7 @@ func isMarker(data []byte) (name string, after []byte) {
|
|||
if i := bytes.IndexByte(data, '\n'); i >= 0 {
|
||||
data, after = data[:i], data[i+1:]
|
||||
}
|
||||
if !bytes.HasSuffix(data, markerEnd) {
|
||||
if !(bytes.HasSuffix(data, markerEnd) && len(data) >= len(marker)+len(markerEnd)) {
|
||||
return "", nil
|
||||
}
|
||||
return strings.TrimSpace(string(data[len(marker) : len(data)-len(markerEnd)])), after
|
||||
|
|
|
@ -29,7 +29,10 @@ More file 1 text.
|
|||
File 2 text.
|
||||
-- empty --
|
||||
-- noNL --
|
||||
hello world`,
|
||||
hello world
|
||||
-- empty filename line --
|
||||
some content
|
||||
-- --`,
|
||||
parsed: &Archive{
|
||||
Comment: []byte("comment1\ncomment2\n"),
|
||||
Files: []File{
|
||||
|
@ -37,6 +40,7 @@ hello world`,
|
|||
{"file 2", []byte("File 2 text.\n")},
|
||||
{"empty", []byte{}},
|
||||
{"noNL", []byte("hello world\n")},
|
||||
{"empty filename line", []byte("some content\n-- --\n")},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
Загрузка…
Ссылка в новой задаче