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

Commit

Permalink
fix: util.addFromURL with URL-escaped file
Browse files Browse the repository at this point in the history
  • Loading branch information
lidel authored and alanshaw committed May 21, 2018
1 parent 966f973 commit a3bd811
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
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

0 comments on commit a3bd811

Please sign in to comment.