Skip to content

Commit

Permalink
Remove encodeURI code
Browse files Browse the repository at this point in the history
The errors that required encodeURIComponent in the past have been
mittigated by the following commit on nextcloud viewer.

nextcloud/viewer@02e1b1a

The code with hasScheme may be removed, viewer now returns a full
properly encoded URI thanks to the work done in nextcloud-router

fixes #381

Signed-off-by: Robbert Gurdeep Singh <[email protected]>
  • Loading branch information
beardhatcode authored and backportbot[bot] committed May 25, 2021
1 parent 5c26079 commit 6bdc13a
Showing 1 changed file with 1 addition and 33 deletions.
34 changes: 1 addition & 33 deletions src/views/PDFView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,41 +33,9 @@ export default {
computed: {
iframeSrc() {
return generateUrl('/apps/files_pdfviewer/?file={file}', {
file: this.encodedDavPath,
file: this.davPath,
})
},

encodedDavPath() {
const hasScheme = this.davPath.indexOf('://') !== -1

if (this.davPath.indexOf(generateUrl('/s/')) === 0) {
const host = window.location.protocol + '//' + window.location.host
const url = new URL(hasScheme ? this.davPath : host + this.davPath)
const path = this.filename.replace(this.basename, '')
url.searchParams.set('path', path)
url.searchParams.set('files', this.basename)
return hasScheme ? url.toString() : url.toString().substr(host.length)
}

const pathSections = this.davPath.split('/')

// Ignore scheme and domain in the loop (note that the scheme
// delimiter, "//", creates an empty section when split by "/").
const initialSection = hasScheme ? 3 : 0

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

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

return encodedDavPath
},
},

async mounted() {
Expand Down

0 comments on commit 6bdc13a

Please sign in to comment.