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

Commit 235a5f2

Browse files
committed
fix: util.addFromURL with URL-escaped file
1 parent faa51b4 commit 235a5f2

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/util/url-add.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ const requestWithRedirect = (url, opts, sendOneFile, callback) => {
5555
qs: opts,
5656
converter: FileResultStreamConverter
5757
}
58+
const fileName = decodeURIComponent(parsedUrl.pathname.split('/').pop())
5859

5960
sendOneFile({
6061
content: res,
61-
path: parsedUrl.pathname.split('/').pop()
62+
path: fileName
6263
}, requestOpts, callback)
6364
}
6465
})

test/util.spec.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ describe('.util', () => {
158158
})
159159

160160
it('with wrap-with-directory=true', (done) => {
161-
ipfs.util.addFromURL('http://ipfs.io/ipfs/QmWjppACLcFLQ2qL38unKQvJBhXH3RUtcGLPk7zmrTwV61/969165.jpg', {
161+
ipfs.util.addFromURL('http://ipfs.io/ipfs/QmWjppACLcFLQ2qL38unKQvJBhXH3RUtcGLPk7zmrTwV61/969165.jpg?foo=bar#buzz', {
162162
wrapWithDirectory: true
163163
}, (err, result) => {
164164
expect(err).to.not.exist()
@@ -170,6 +170,20 @@ describe('.util', () => {
170170
})
171171
})
172172

173+
it('with wrap-with-directory=true and URL-escaped file name', (done) => {
174+
// Sample URL contains URL-escaped ( ) and local diacritics
175+
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', {
176+
wrapWithDirectory: true
177+
}, (err, result) => {
178+
expect(err).to.not.exist()
179+
expect(result[0].hash).to.equal('QmRJ9ExxSMV4BLF9ZJUb2mLngupm6BXZEek755VHGTJo2Y')
180+
expect(result[0].path).to.equal('320px-Domažlice,_Jiráskova_43_(9102).jpg')
181+
expect(result[1].hash).to.equal('QmbxsHFU3sCfr8wszDHuDLA76C2xCv9HT8L3aC1pBwgaHk')
182+
expect(result.length).to.equal(2)
183+
done()
184+
})
185+
})
186+
173187
it('with invalid url', function (done) {
174188
ipfs.util.addFromURL('http://invalid', (err, result) => {
175189
expect(err.code).to.equal('ENOTFOUND')

0 commit comments

Comments
 (0)