Skip to content

Commit

Permalink
Fix opening PDF files with special characters in their name
Browse files Browse the repository at this point in the history
Before the move to the viewer the URL of the PDF file to load was got
using "Files.getDownloadUrl()", which encodes each section of the path
as a URI component. The full URL, in turn, was again encoded as a URI
component to set the source of the iframe in which the PDF viewer is
loaded. When the PDF viewer parsed the URL it decoded it once, so each
section of the path was still encoded as a URI component.

After the move to the viewer the URL of the PDF file to load was got
from the "davPath" property set by the viewer, which uses the filename
as is. The full URL was then encoded as a URI component, so when the PDF
viewer parsed and decoded the URL the raw filename was used. In most
cases it worked fine, but if the filename included some special
character, like "?", the file failed to load.

Now, instead of using the "davPath" property set by the viewer, each
section of the dav path is encoded as a URI component. The encoding
tries to not make any assumption on the format used by the viewer to
avoid being coupled too much.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
  • Loading branch information
danxuliu authored and backportbot[bot] committed Jan 28, 2021
1 parent 57625d4 commit 46829d8
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/views/PDFView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,32 @@ export default {
computed: {
iframeSrc() {
return generateUrl('/apps/files_pdfviewer/?file={file}', {
file: this.davPath,
file: this.encodedDavPath,
})
},
encodedDavPath() {
const hasScheme = this.davPath.indexOf('://') !== -1
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 46829d8

Please sign in to comment.