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

Support "+" character in file paths #588

Merged
merged 1 commit into from
Sep 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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