Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
feat: Preserve "+" in file paths. (#588)
Browse files Browse the repository at this point in the history
  • Loading branch information
petethomas authored and daviddias committed Sep 1, 2017
1 parent 688d918 commit 322b756
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/utils/get-files-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const flatmap = require('flatmap')
const escape = require('glob-escape')

function headers (file) {
const name = file.path || ''
const name = encodeURIComponent(file.path) || ''
const header = {
'Content-Disposition': `file; filename="${name}"`
}
Expand Down
31 changes: 31 additions & 0 deletions test/get.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,37 @@ describe('.get', () => {
})
})
})

it('add path containing "+"s (for testing get)', (done) => {
if (!isNode) { return done() }
const filename = 'ti,c64x+mega++mod-pic.txt'
const subdir = 'tmp/c++files'
const expectedMultihash = 'QmPkmARcqjo5fqK1V1o8cFsuaXxWYsnwCNLJUYS4KeZyff'
ipfs.files.add([{
path: subdir + '/' + filename,
content: Buffer.from(subdir + '/' + filename, 'utf-8')
}], (err, res) => {
if (err) done(err)
expect(res[2].hash).to.equal(expectedMultihash)
done()
})
})

it('get path containing "+"s', (done) => {
if (!isNode) { return done() }
const multihash = 'QmPkmARcqjo5fqK1V1o8cFsuaXxWYsnwCNLJUYS4KeZyff'
let count = 0
ipfs.get(multihash, (err, files) => {
expect(err).to.not.exist()
files.on('data', (file) => {
if (file.path !== multihash) {
count++
expect(file.path).to.contain('+')
if (count === 2) done()
}
})
})
})
})

describe('Promise API', () => {
Expand Down

0 comments on commit 322b756

Please sign in to comment.