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

fix: Improve compatibility with Windows for uploaded files #2513

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Koc
Copy link
Collaborator

@Koc Koc commented Jan 23, 2025

Fixes #2409

Copy link

codecov bot commented Jan 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 43.40%. Comparing base (f8fca97) to head (3859656).
Report is 46 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #2513   +/-   ##
=========================================
  Coverage     43.40%   43.40%           
  Complexity      882      882           
=========================================
  Files            77       77           
  Lines          3359     3359           
=========================================
  Hits           1458     1458           
  Misses         1901     1901           

@Koc Koc force-pushed the bugfix/improve-windows-compatibility branch from ecdefa9 to 556303e Compare January 23, 2025 01:08
@@ -44,6 +44,19 @@
* @psalm-import-type FormsShare from ResponseDefinitions
*/
class FormsService {
private const FILENAME_INVALID_CHARS = [
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you move this to the Constants? And how about using the OCP constants and just combining it with the remaining ones?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Neither of it just use OCP\Files\IFilenameValidator and I do not think we should replace them but forbid upload of files containing them.
But also do it in the fronend:

nextcloud-files validateFilename

Copy link
Collaborator

@Chartman123 Chartman123 Jan 23, 2025

Choose a reason for hiding this comment

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

Ok, didn't know about that :) But yes, then I agree: we should already use the validation upon uploading the files in the frontend and the backend, so that we don't have to manipulate the filenames afterwards.

Copy link
Collaborator

Choose a reason for hiding this comment

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

But one thing remains: The folder structure is based on the question titles. So if you for example put a : in the title of a file question, the corresponding folders can't be sync'ed on Windows devices.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok, so I've moved FILENAME_INVALID_CHARS into Constants class. Regarding other hints:

  • combining OCP\Constants::FILENAME_INVALID_CHARS + \OCA\Forms\Constants::FILENAME_INVALID_CHARS has no sense for me because I've defined invalid chars as an array but global invalid characters defined as string. Array is better here because we don't need call mb_str_split all the time
  • IFilenameValidator - we're already calling $userFolder->getStorage()->verifyPath($path, $uploadedFile['name']); during file upload. Is it not enough? Even more, as already mentioned, uploaded file can have correct name, but due to form/question name path can be invalid

Anyway, feel free to force-push any changes into my branch.

@Koc Koc force-pushed the bugfix/improve-windows-compatibility branch 3 times, most recently from 513f4fa to c7fdda8 Compare January 29, 2025 14:22
@Koc Koc force-pushed the bugfix/improve-windows-compatibility branch from c7fdda8 to 3859656 Compare January 29, 2025 15:23
Copy link

github-actions bot commented Feb 6, 2025

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

(If you believe you should not receive this message, you can add yourself to the blocklist.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The Forms folder structure is not sanitized which can lead to synchronization issues when uploading files
3 participants