Skip to content

Commit 9b50651

Browse files
committed
Fix saving annotations in paths with special characters
The filename may contain characters that are not compatible with a URL path, so it needs to be explicitly encoded. Otherwise the upload could fail (for example, if the filename contains "%" followed by a letter, which would cause the server to fail to decode the path and return a "400 Bad request" error) or even overwrite a different file (for example, if the filename contains "#", which would cause the rest of the path to be ignored). Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
1 parent 2cf4704 commit 9b50651

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/services/uploadPdfFile.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
import { getRequestToken } from '@nextcloud/auth'
66
import axios from '@nextcloud/axios'
7+
import { encodePath } from '@nextcloud/paths'
78

89
import { getRootPath } from '../utils/davUtils.js'
910
import { getSharingToken } from '@nextcloud/sharing/public'
@@ -25,7 +26,7 @@ import { getSharingToken } from '@nextcloud/sharing/public'
2526
export default async function(filename, data) {
2627
// getRootPath takes into account the differences between files of
2728
// registered users and public shares.
28-
const filePath = getRootPath() + filename
29+
const filePath = getRootPath() + encodePath(filename)
2930

3031
const blob = new Blob([data], { type: 'application/pdf' })
3132

0 commit comments

Comments
 (0)