Skip to content

Commit 0b4e2db

Browse files
committed
Fix viewing PDF files with public share links
In #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.
1 parent b6f8b52 commit 0b4e2db

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

src/views/PDFView.vue

+8-16
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,18 @@ export default {
3838
},
3939

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

43-
const pathSections = this.davPath.split('/')
45+
url.pathname = pathname
4446

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

49-
let encodedDavPath = ''
50-
for (let i = initialSection; i < pathSections.length; i++) {
51-
if (pathSections[i] !== '') {
52-
encodedDavPath += '/' + encodeURIComponent(pathSections[i])
53-
}
54-
}
50+
const encodedDavPath = url.toString()
5551

56-
if (hasScheme) {
57-
encodedDavPath = pathSections[0] + '//' + pathSections[2] + encodedDavPath
58-
}
59-
60-
return encodedDavPath
52+
return hasScheme ? encodedDavPath : encodedDavPath.split('https://.')[1]
6153
},
6254
},
6355

0 commit comments

Comments
 (0)