-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix opening PDF files with special characters in their name #291
Fix opening PDF files with special characters in their name #291
Conversation
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>
/backport to stable20 |
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 | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The question is: shouldn't this be on Viewer? we have the same issue for other files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that question is in the pull request description...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and works 👍
SO go or no go? |
I would say merge now and then adjust later if it is fixed in the viewer instead of the PDF viewer. Otherwise Nextcloud 21 could end shipping with the issue. |
Before the move to the viewer the URL of the PDF file to load was got (indirectly) 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.I do not know if this should be something to be fixed in the viewer instead (although images with "?" in their name load fine 🤷). However, even in that case, this should fix the PDF viewer until the changes in the viewer are ready.
How to test
test?.pdf
Result with this pull request
The file is opened in the viewer.
Result without this pull request
The viewer opens, but the file fails to open.