Skip to content

Commit

Permalink
txtar/archive: ignore invalid file separators
Browse files Browse the repository at this point in the history
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 <[email protected]>
gopls-CI: kokoro <[email protected]>
Reviewed-by: Jay Conrod <[email protected]>
Trust: Jay Conrod <[email protected]>
Trust: Michael Matloob <[email protected]>
TryBot-Result: Go Bot <[email protected]>
  • Loading branch information
Paschalis Tsilias authored and Jay Conrod committed Jul 26, 2021
1 parent 4fe0d6c commit ebce39e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion txtar/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion txtar/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@ 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{
{"file1", []byte("File 1 text.\n-- foo ---\nMore file 1 text.\n")},
{"file 2", []byte("File 2 text.\n")},
{"empty", []byte{}},
{"noNL", []byte("hello world\n")},
{"empty filename line", []byte("some content\n-- --\n")},
},
},
},
Expand Down

0 comments on commit ebce39e

Please sign in to comment.