Skip to content

Commit

Permalink
fix: Encode individual parts of the dav url as uri components
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <jus@bitgrid.net>
  • Loading branch information
juliushaertl authored and backportbot-nextcloud[bot] committed Jul 12, 2023
1 parent 5f5b2e8 commit 35a263a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/services/AttachmentResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export default class AttachmentResolver {
#davUrl(src) {
if (this.#user) {
const uid = this.#user.uid
const encoded = encodeURI(this.#filePath(src))
const encoded = this.#filePath(src).split('/').map(encodeURIComponent).join('/')
return generateRemoteUrl(`dav/files/${uid}${encoded}`)
}

Expand Down
9 changes: 9 additions & 0 deletions src/tests/services/AttachmentResolver.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ describe('Image resolver', () => {
expect(candidate.url).toBe('/nc-webroot/apps/files_sharing/publicpreview/SHARE_TOKEN?file=%2FMedia%2Fphoto.jpeg&x=1024&y=1024&a=true')
})

it('handles .attachments urls with special characters', async () => {
const src = `.attachments.${session.documentId + 1}/group #1/test #2.jpg`
const resolver = new AttachmentResolver({ session, user, currentDirectory: '/myCurrentDir #1' })
const [candidate, fallbackCandidate, secondFallback] = await resolver.resolve(src)

expect(candidate.type).toBe('image')
expect(candidate.url).toBe('http://localhost/nc-webroot/remote.php/dav/files/user-uid/myCurrentDir%20%231/.attachments.4174/group%20%231/test%20%232.jpg')
})

it('handles .attachments urls to different fileId via webdav with text API fallback', async () => {
const src = `.attachments.${session.documentId + 1}/group%20pic.jpg`
const resolver = new AttachmentResolver({ session, user, currentDirectory })
Expand Down

0 comments on commit 35a263a

Please sign in to comment.