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

fix(util): addFromURL with URL-escaped file names #764

Merged
merged 1 commit into from
May 21, 2018
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
3 changes: 2 additions & 1 deletion src/util/url-add.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ const requestWithRedirect = (url, opts, sendOneFile, callback) => {
qs: opts,
converter: FileResultStreamConverter
}
const fileName = decodeURIComponent(parsedUrl.pathname.split('/').pop())

sendOneFile({
content: res,
path: parsedUrl.pathname.split('/').pop()
path: fileName
}, requestOpts, callback)
}
})
Expand Down
16 changes: 15 additions & 1 deletion test/util.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ describe('.util', () => {
})

it('with wrap-with-directory=true', (done) => {
ipfs.util.addFromURL('http://ipfs.io/ipfs/QmWjppACLcFLQ2qL38unKQvJBhXH3RUtcGLPk7zmrTwV61/969165.jpg', {
ipfs.util.addFromURL('http://ipfs.io/ipfs/QmWjppACLcFLQ2qL38unKQvJBhXH3RUtcGLPk7zmrTwV61/969165.jpg?foo=bar#buzz', {
wrapWithDirectory: true
}, (err, result) => {
expect(err).to.not.exist()
Expand All @@ -173,6 +173,20 @@ describe('.util', () => {
})
})

it('with wrap-with-directory=true and URL-escaped file name', (done) => {
// Sample URL contains URL-escaped ( ) and local diacritics
ipfs.util.addFromURL('https://upload.wikimedia.org/wikipedia/commons/thumb/c/cf/Doma%C5%BElice%2C_Jir%C3%A1skova_43_%289102%29.jpg/320px-Doma%C5%BElice%2C_Jir%C3%A1skova_43_%289102%29.jpg?foo=bar#buzz', {
wrapWithDirectory: true
}, (err, result) => {
expect(err).to.not.exist()
expect(result[0].hash).to.equal('QmRJ9ExxSMV4BLF9ZJUb2mLngupm6BXZEek755VHGTJo2Y')
expect(result[0].path).to.equal('320px-Domažlice,_Jiráskova_43_(9102).jpg')
expect(result[1].hash).to.equal('QmbxsHFU3sCfr8wszDHuDLA76C2xCv9HT8L3aC1pBwgaHk')
expect(result.length).to.equal(2)
done()
})
})

it('with invalid url', function (done) {
ipfs.util.addFromURL('http://invalid', (err, result) => {
expect(err.code).to.equal('ENOTFOUND')
Expand Down