aboutsummaryrefslogtreecommitdiff
path: root/src/archive/tar/reader_test.go
diff options
context:
space:
mode:
authorJoe Tsai <joetsai@digital-static.net>2017-10-06 01:40:58 -0700
committerJoe Tsai <thebrokentoaster@gmail.com>2017-10-10 20:11:26 +0000
commit4cd58c2f2687fc5930a3da2581da09e2e96f69f5 (patch)
tree5202f0d1add6e08819620606bd1fecbf1bb610d9 /src/archive/tar/reader_test.go
parentd63de2871163dea94f3d5df83374f8b5e7e8677d (diff)
downloadgo-4cd58c2f2687fc5930a3da2581da09e2e96f69f5.tar.xz
archive/tar: improve handling of directory paths
The USTAR format says: <<< Implementors should be aware that the previous file format did not include a mechanism to archive directory type files. For this reason, the convention of using a filename ending with <slash> was adopted to specify a directory on the archive. >>> In light of this suggestion, make the following changes: * Writer.WriteHeader refuses to encode a header where a file that is obviously a file-type has a trailing slash in the name. * formatter.formatString avoids encoding a trailing slash in the event that the string is truncated (the full string will be encoded elsewhere, so stripping the slash is safe). * Reader.Next treats a TypeRegA (which is the zero value of Typeflag) as a TypeDir if the name has a trailing slash. Change-Id: Ibf27aa8234cce2032d92e5e5b28546c2f2ae5ef6 Reviewed-on: https://go-review.googlesource.com/69293 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/archive/tar/reader_test.go')
-rw-r--r--src/archive/tar/reader_test.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/archive/tar/reader_test.go b/src/archive/tar/reader_test.go
index bbabd96246..3ac81adb4d 100644
--- a/src/archive/tar/reader_test.go
+++ b/src/archive/tar/reader_test.go
@@ -675,6 +675,17 @@ func TestReader(t *testing.T) {
},
Format: FormatPAX,
}},
+ }, {
+ file: "testdata/trailing-slash.tar",
+ headers: []*Header{{
+ Typeflag: TypeDir,
+ Name: strings.Repeat("123456789/", 30),
+ ModTime: time.Unix(0, 0),
+ PAXRecords: map[string]string{
+ "path": strings.Repeat("123456789/", 30),
+ },
+ Format: FormatPAX,
+ }},
}}
for _, v := range vectors {