Skip to content

Commit

Permalink
fix!: add escaped abspath header
Browse files Browse the repository at this point in the history
Adds new 'abspath-encoded' header to MultiFileReader.
New server sends both headers. New client prefers
'abspath-encoded' over 'abspath'. Old clients won't
be compatible with new servers.
  • Loading branch information
hacdias committed Aug 16, 2023
1 parent b96767c commit 20859fa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ The following emojis are used to highlight certain changes:

### Fixed

* 🛠 `MultiFileReader` has been updated with a new header with the encoded file
name instead of the plain filename, due to a regression found in
[`net/textproto`](https://github.com/golang/go/issues/60674). This only affects
files with binary characters in their name. By keeping the old header, we maximize
backwards compatibility.
| | New Client | Old Client |
|------------|------------|-------------|
| New Server |||
| Old Server |||

### Security

## [v0.11.0]
Expand Down
1 change: 1 addition & 0 deletions files/multifilereader.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func (mfr *MultiFileReader) Read(buf []byte) (written int, err error) {
header.Set("Content-Type", contentType)
if rf, ok := entry.Node().(FileInfo); ok {
header.Set("abspath", rf.AbsPath())
header.Set("abspath-encoded", url.QueryEscape(rf.AbsPath()))
}

_, err := mfr.mpWriter.CreatePart(header)
Expand Down
12 changes: 11 additions & 1 deletion files/multipartfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,19 @@ func (w *multipartWalker) nextFile() (Node, error) {

return NewLinkFile(string(out), nil), nil
default:
var absPath string
if absPathEncoded := part.Header.Get("abspath-encoded"); absPathEncoded != "" {
absPath, err = url.QueryUnescape(absPathEncoded)
if err != nil {
return nil, err
}

Check warning on line 108 in files/multipartfile.go

View check run for this annotation

Codecov / codecov/patch

files/multipartfile.go#L105-L108

Added lines #L105 - L108 were not covered by tests
} else {
absPath = part.Header.Get("abspath")
}

return &ReaderFile{
reader: part,
abspath: part.Header.Get("abspath"),
abspath: absPath,
}, nil
}
}
Expand Down

0 comments on commit 20859fa

Please sign in to comment.