-
Notifications
You must be signed in to change notification settings - Fork 14
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
#4094 - File Issues - Comma in file name #4153
Conversation
sources/packages/backend/apps/api/src/route-controllers/student/student.controller.service.ts
Outdated
Show resolved
Hide resolved
response.setHeader( | ||
"Content-Disposition", | ||
`attachment; filename=${studentFile.fileName}`, | ||
`attachment; filename*=UTF-8''${encodedFileName}`, |
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.
Great finding.
I see that it follows the Extended notation
example from RFC5987
I believe the encodeURIComponent()
sufficient not required to do further replace as stated here.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent#examples
Thoughts ?
@andrewsignori-aot @andrepestana-aot @guru-aot @lewischen-aot
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.
Agreed @dheepak-aot
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.
Looks good.
response.setHeader( | ||
"Content-Disposition", | ||
`attachment; filename=${studentFile.fileName}`, | ||
`attachment; filename*=UTF-8''${encodedFileName}`, |
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.
Please move this logic of creating encoded file name to a common util.
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.
Moved to String utils
* @returns Object containing encoded filename | ||
*/ | ||
export function encodeFileNameForContentDisposition(fileName: string): string { | ||
const encodedFileName = encodeURIComponent(fileName); |
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.
As we are just using encodeURIComponent
please remove the util as the purpose seems to be more linear.
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.
removed the utils func
|
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.
Thanks for making the changes @bidyashish. Looks good 👍
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.
Looks good!
**Technical Details** - [x] Ensure the file name is escaped while downloading to prevent the issue with the comma and some other potential characters. - [x] Add an E2E test with some scenarios to test different characters. - [ ] This should be added to v2.2 branch. Demo: Able to Download File with Comma ![image](https://github.com/user-attachments/assets/82bd65d5-ed65-41b2-b252-edad13b07fa8) ![image](https://github.com/user-attachments/assets/dca924d4-1e2a-4727-8b70-deab9b95f060)
**Technical Details** - [x] Ensure the file name is escaped while downloading to prevent the issue with the comma and some other potential characters. - [x] Add an E2E test with some scenarios to test different characters. - [x] This should be added to v2.2 branch. Demo: Able to Download File with Comma ![image](https://github.com/user-attachments/assets/82bd65d5-ed65-41b2-b252-edad13b07fa8) ![image](https://github.com/user-attachments/assets/dca924d4-1e2a-4727-8b70-deab9b95f060)
Technical Details
Demo:
![image](https://private-user-images.githubusercontent.com/14001930/397171361-82bd65d5-ed65-41b2-b252-edad13b07fa8.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5MjczNDQsIm5iZiI6MTczODkyNzA0NCwicGF0aCI6Ii8xNDAwMTkzMC8zOTcxNzEzNjEtODJiZDY1ZDUtZWQ2NS00MWIyLWIyNTItZWRhZDEzYjA3ZmE4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA3VDExMTcyNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWRiYjI3ZGY4YWVkOTA5N2UxYmI2YTYyOGU3NDE2NTY4MjI1OGZiYTMyNTc3ZDUxN2NlODM3ZmNmMDQ5MDg0YjMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.m4ON_SzgwLaKNddjSosjDmSK3doU7cKVPB8WUpfvl4I)
![image](https://private-user-images.githubusercontent.com/14001930/397171501-dca924d4-1e2a-4727-8b70-deab9b95f060.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5MjczNDQsIm5iZiI6MTczODkyNzA0NCwicGF0aCI6Ii8xNDAwMTkzMC8zOTcxNzE1MDEtZGNhOTI0ZDQtMWUyYS00NzI3LThiNzAtZGVhYjliOTVmMDYwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA3VDExMTcyNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTg1ZmRlMDEzMDc4MmE0YmY3OWRhODJmNmQxMjg3YTMwZTc3MDAyMzNiZDc2MDk1ZmMzNWI5ZWUwOGE2ZDVjMDAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.Yrw8l-UTwZri2i4H8G8-wTg-POEFSMNaeplCf3lWk5Q)
Able to Download File with Comma