Skip to content
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

Fixes for Non-ASCII filenames #117

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/Item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const template = (entry: Entry): string => `<li tabindex="0" data-full-path="${
<span class="title">${entry.title}</span>
<input type="text" name="rename" class="hidden" readonly>
<span class="size">${entry.displaySize}</span>
<a href="${entry.fullPath}" download="${entry.name}" title="${t(
<a href="${entry.fullPath}" download="${decodeURI(entry.name)}" title="${t(
'download'
)} (⇧+⏎)"></a>
<a href="#" title="${t('copy')}" class="copy"></a>
Expand Down Expand Up @@ -491,7 +491,7 @@ export default class Item extends Element {
const destinationPath = joinPath(entry.path, input.value),
result = await this.#dav.move(
entry.fullPath,
destinationPath,
encodeURI(destinationPath),
entry
);

Expand Down
5 changes: 4 additions & 1 deletion src/lib/handleFileUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ export const handleFileUpload = async (

state.setCollection(collection);

// NOTE: we can't use entry.name === encodeURI(file.name) here,
// because server and encodeURI() might use different case for
// %-encoded values, like "%D0" vs "%d0"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: To avoid this problem we could toUpperCase()/toLowerCase() too. If you think it's valuable, but I have no problem with this approach either.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this won't work because toUpperCase()/toLowerCase() will also change case of other letters in filename. For example, if server says that it has a file called A%2dFile.txt, and we try to upload a file called A%2DFile.txt (different case of letter "D"), then toUpperCase() and toLowerCase() will turn it to A%2DFILE.TXT and a%2dfile.txt, respectively, which won't match filename on the server.

We could convert both filenames to upper case, but then we would assume that backend server case-insensitive, and uploading a file called FILE.TXT overwrites a file called file.txt. Which is actually a case only on Windows.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely. Another alternative could be decoding and re-encoding so that the case (should?) be consistent as it's using the browser to perform the encode both sides. For .toUpperCase() we could .replace(/%[0-9a-f]{2}/g, (s) => s.toUpperCase()) although I wonder if we'll encounter problems with values like %252d/%252D etc.

const [existingFile] = collection.filter(
(entry: Entry): boolean => entry.name === file.name
(entry: Entry): boolean => decodeURI(entry.name) === file.name
);

if (existingFile) {
Expand Down
Loading