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 60879 #8344

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Fix 60879 #8344

wants to merge 5 commits into from

Conversation

larkox
Copy link
Contributor

@larkox larkox commented Nov 13, 2024

Summary

Fix 60879

Ticket Link

Fix https://mattermost.atlassian.net/browse/MM-60879
Fix #8359

Release Note

NONE

@larkox larkox added 2: Dev Review Requires review by a core commiter 3: QA Review Requires review by a QA tester labels Nov 13, 2024
Copy link
Contributor

@enahum enahum left a comment

Choose a reason for hiding this comment

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

Why in some places we use the safe and in others we dont?

@larkox
Copy link
Contributor Author

larkox commented Nov 14, 2024

@enahum From what I have tested, filenames usually are not encoded, so they don't need decoding.

On the other hand (and this is mostly a guess) links should be encoded, and it makes sense to decode them to get the file name.

@enahum
Copy link
Contributor

enahum commented Nov 14, 2024

@enahum From what I have tested, filenames usually are not encoded, so they don't need decoding.

On the other hand (and this is mostly a guess) links should be encoded, and it makes sense to decode them to get the file name.

Can you try a pdf file with spaces attached to a post.. I'm sure there is a reason why it was done this way at some point.. I just don't remember why it was

Copy link
Contributor

@rahimrahman rahimrahman left a comment

Choose a reason for hiding this comment

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

I have a question in regards to the file naming. Curious if you name the file as sampled and will it get decoded to a file name that doesn't exist?

Comment on lines 258 to 259
const result = decodeURIComponent(v);
return result;
Copy link
Contributor

Choose a reason for hiding this comment

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

small nit:

Suggested change
const result = decodeURIComponent(v);
return result;
return decodeURIComponent(v);

@@ -88,7 +88,7 @@ const MarkdownImage = ({
const uri = source.startsWith('/') ? serverUrl + source : source;

const fileInfo = useMemo(() => {
const link = decodeURIComponent(uri);
const link = safeDecodeURIComponent(uri);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we test this?

An image file with hello%253Fworld.jpg. Would it get decoded into hello%3Fworld.jpg thus causing the file not to be found?

@@ -273,7 +273,7 @@ const DownloadWithAction = ({action, item, onDownloadSuccess, setAction, gallery
actionToExecute({
code: 200,
ok: true,
data: {path},
data: {path: path.replace('file://', '')},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This may not be related, but I was having issues with some files due to this ending up with a filename file://file://.

@larkox
Copy link
Contributor Author

larkox commented Nov 26, 2024

After my testing, I think everything should be handled correctly, but further testing is always welcomed.

@yasserfaraazkhan As testing notes:

  • Try uploading and dowloading normal files, from different types
  • Try some of those files with % in their names
  • Try also markdown images with % in their links
  • And finally, try markdown images with % in their links within a table

enahum
enahum previously approved these changes Nov 26, 2024
Copy link
Contributor

@enahum enahum left a comment

Choose a reason for hiding this comment

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

Lgtm

@enahum enahum dismissed their stale review November 26, 2024 12:44

Needs tests at least for the new utility function

@@ -252,3 +252,11 @@ export function extractFilenameFromUrl(url: string) {
const uri = urlParse(url);
return uri.pathname.split('/').pop();
}

export function safeDecodeURIComponent(v: string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add tests to this

@larkox larkox requested a review from enahum November 26, 2024 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2: Dev Review Requires review by a core commiter 3: QA Review Requires review by a QA tester release-note-none
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The mobile client crash due to the file name in the channel
4 participants