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

Add filename sanitization #1336

Merged
merged 7 commits into from
May 16, 2024

Conversation

Caesarovich
Copy link
Contributor

-> Fixes issue #1063 #1180 #1101 (And possibly more but I couldn't find)

Description

As discussed in issue #1063 there currently is an error if a file is sent on a device with a different system of the sender. This is due to different character limitations in files' names depending on Operating systems and partitions. For example:

On my Linux computer I can create the file <cool>.txt and send it to my other linux computer without issue. But if I try to send it to my Windows computer or to my Android phone, LocalSend will fail to save the file and fail the transfer with error code 500. This is because <> are illegal characters on Windows and FAT32 devices (Android).

This PR fixes that issue by providing a sanitization step before saving a file. Like here:

Future<String> digestFilePathAndPrepareDirectory({required String parentDirectory, required String fileName}) async {
  final actualFileName = legalizeFilename(p.basename(fileName), os: Platform.operatingSystem); // <- here
  final fileNameParts = p.split(fileName);
  .....

The sanitization is handled by the legalize library that I made for the occasion. So if any issues like this open up, they can be addressed upstream here instead. I'd be glad if users could test it across the many different OS they possess, I couldn't test it directly on all the possible different systems.

Changes

  • Now includes the legalize: 1.2.1 dependency
  • Filename sanitization in the digestFilePathAndPrepareDirectory function
  • Filename check for the FileNameInputDialog and QuickActionsDialog widgets

@Caesarovich
Copy link
Contributor Author

I've lowered the SDK requirements :)

@Tienisto
Copy link
Member

Thank you!

@Tienisto Tienisto merged commit 66af173 into localsend:main May 16, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants