Skip to content

Commit

Permalink
Fix viewing PDF files with public share links
Browse files Browse the repository at this point in the history
In nextcloud#286, users have reported that PDF files
are not viewable via public share links. The issue was introduced in
c992b55 when attempting to encode parts of the URL for files that
have special characters.

This patch uses the URL Web API to deal with the parts of the URL
in a more specific way. Also, the path and files searchParams are
set based on `this.filename` and `this.basename` in the same way
it is done in the View module when setting `davPath`.

This has been tested on private and shared public links on files
with and without special characters.
  • Loading branch information
wankdanker committed Feb 10, 2021
1 parent b6f8b52 commit e5667ad
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions src/views/PDFView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,19 @@ export default {
},

encodedDavPath() {
const hasScheme = this.davPath.indexOf('://') !== -1
const hasScheme = ~this.davPath.indexOf('://')
const url = new URL(hasScheme ? this.davPath : 'https://.' + this.davPath)

const pathSections = this.davPath.split('/')
url.pathname = url.pathname.split('/')
.map(encodeURIComponent)
.join('/')

// Ignore scheme and domain in the loop (note that the scheme
// delimiter, "//", creates an empty section when split by "/").
const initialSection = hasScheme ? 3 : 0
url.searchParams.set('path', this.filename.replace(this.basename, ''))
url.searchParams.set('files', this.basename)

let encodedDavPath = ''
for (let i = initialSection; i < pathSections.length; i++) {
if (pathSections[i] !== '') {
encodedDavPath += '/' + encodeURIComponent(pathSections[i])
}
}
const encodedDavPath = url.toString()

if (hasScheme) {
encodedDavPath = pathSections[0] + '//' + pathSections[2] + encodedDavPath
}

return encodedDavPath
return hasScheme ? encodedDavPath : encodedDavPath.split('https://.')[1]
},
},

Expand Down

0 comments on commit e5667ad

Please sign in to comment.