Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 322b756

Browse files
petethomasdaviddias
authored andcommitted
feat: Preserve "+" in file paths. (#588)
1 parent 688d918 commit 322b756

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/utils/get-files-stream.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const flatmap = require('flatmap')
66
const escape = require('glob-escape')
77

88
function headers (file) {
9-
const name = file.path || ''
9+
const name = encodeURIComponent(file.path) || ''
1010
const header = {
1111
'Content-Disposition': `file; filename="${name}"`
1212
}

test/get.spec.js

+31
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,37 @@ describe('.get', () => {
156156
})
157157
})
158158
})
159+
160+
it('add path containing "+"s (for testing get)', (done) => {
161+
if (!isNode) { return done() }
162+
const filename = 'ti,c64x+mega++mod-pic.txt'
163+
const subdir = 'tmp/c++files'
164+
const expectedMultihash = 'QmPkmARcqjo5fqK1V1o8cFsuaXxWYsnwCNLJUYS4KeZyff'
165+
ipfs.files.add([{
166+
path: subdir + '/' + filename,
167+
content: Buffer.from(subdir + '/' + filename, 'utf-8')
168+
}], (err, res) => {
169+
if (err) done(err)
170+
expect(res[2].hash).to.equal(expectedMultihash)
171+
done()
172+
})
173+
})
174+
175+
it('get path containing "+"s', (done) => {
176+
if (!isNode) { return done() }
177+
const multihash = 'QmPkmARcqjo5fqK1V1o8cFsuaXxWYsnwCNLJUYS4KeZyff'
178+
let count = 0
179+
ipfs.get(multihash, (err, files) => {
180+
expect(err).to.not.exist()
181+
files.on('data', (file) => {
182+
if (file.path !== multihash) {
183+
count++
184+
expect(file.path).to.contain('+')
185+
if (count === 2) done()
186+
}
187+
})
188+
})
189+
})
159190
})
160191

161192
describe('Promise API', () => {

0 commit comments

Comments
 (0)