diff --git a/txtar/archive.go b/txtar/archive.go index c384f33bd..214256617 100644 --- a/txtar/archive.go +++ b/txtar/archive.go @@ -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 diff --git a/txtar/archive_test.go b/txtar/archive_test.go index 7ac5ee9dd..6534f5301 100644 --- a/txtar/archive_test.go +++ b/txtar/archive_test.go @@ -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")}, }, }, },