Skip to content

Commit e5667ad

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 e5667ad

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

src/views/PDFView.vue

+9-16
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,19 @@ 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)
4243

43-
const pathSections = this.davPath.split('/')
44+
url.pathname = url.pathname.split('/')
45+
.map(encodeURIComponent)
46+
.join('/')
4447

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
48+
url.searchParams.set('path', this.filename.replace(this.basename, ''))
49+
url.searchParams.set('files', this.basename)
4850

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

56-
if (hasScheme) {
57-
encodedDavPath = pathSections[0] + '//' + pathSections[2] + encodedDavPath
58-
}
59-
60-
return encodedDavPath
53+
return hasScheme ? encodedDavPath : encodedDavPath.split('https://.')[1]
6154
},
6255
},
6356

0 commit comments

Comments
 (0)