From 5881bc9ab047c547e486090871585585067b1ff4 Mon Sep 17 00:00:00 2001 From: Oleg Lobanov Date: Wed, 5 Aug 2020 10:40:03 +0200 Subject: [PATCH] chore: fix preview of files with non-latin names (closes #1056) --- frontend/src/components/files/Preview.vue | 6 +++--- frontend/src/utils/url.js | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/files/Preview.vue b/frontend/src/components/files/Preview.vue index f2c39092..2e89b92c 100644 --- a/frontend/src/components/files/Preview.vue +++ b/frontend/src/components/files/Preview.vue @@ -99,13 +99,13 @@ export default { return (this.nextLink !== '') }, download () { - return `${baseURL}/api/raw${escape(this.req.path)}?auth=${this.jwt}` + return `${baseURL}/api/raw${url.encodePath(this.req.path)}?auth=${this.jwt}` }, previewUrl () { if (this.req.type === 'image') { - return `${baseURL}/api/preview/big${escape(this.req.path)}?auth=${this.jwt}` + return `${baseURL}/api/preview/big${url.encodePath(this.req.path)}?auth=${this.jwt}` } - return `${baseURL}/api/raw${escape(this.req.path)}?auth=${this.jwt}` + return `${baseURL}/api/raw${url.encodePath(this.req.path)}?auth=${this.jwt}` }, raw () { return `${this.previewUrl}&inline=true` diff --git a/frontend/src/utils/url.js b/frontend/src/utils/url.js index 44779d3a..30e0a658 100644 --- a/frontend/src/utils/url.js +++ b/frontend/src/utils/url.js @@ -20,7 +20,12 @@ function encodeRFC5987ValueChars(str) { replace(/%(?:7C|60|5E)/g, unescape); } +function encodePath(str) { + return str.split('/').map(v => encodeURIComponent(v)).join('/') +} + export default { encodeRFC5987ValueChars: encodeRFC5987ValueChars, - removeLastDir: removeLastDir + removeLastDir: removeLastDir, + encodePath: encodePath }