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

#4094 - File Issues - Comma in file name #4153

Merged
merged 8 commits into from
Dec 19, 2024

Conversation

bidyashish
Copy link
Collaborator

@bidyashish bidyashish commented Dec 19, 2024

Technical Details

  • Ensure the file name is escaped while downloading to prevent the issue with the comma and some other potential characters.
  • 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
image

@bidyashish bidyashish self-assigned this Dec 19, 2024
@bidyashish bidyashish added the Student Student Features label Dec 19, 2024
@dheepak-aot dheepak-aot self-requested a review December 19, 2024 00:25
response.setHeader(
"Content-Disposition",
`attachment; filename=${studentFile.fileName}`,
`attachment; filename*=UTF-8''${encodedFileName}`,
Copy link
Collaborator

@dheepak-aot dheepak-aot Dec 19, 2024

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
image

Thoughts ?
@andrewsignori-aot @andrepestana-aot @guru-aot @lewischen-aot

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agreed @dheepak-aot

Copy link
Collaborator

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}`,
Copy link
Collaborator

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.

Copy link
Collaborator Author

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);
Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed the utils func

Copy link

Backend Unit Tests Coverage Report

Totals Coverage
Statements: 22.08% ( 3783 / 17133 )
Methods: 10.07% ( 219 / 2175 )
Lines: 25.47% ( 3278 / 12868 )
Branches: 13.68% ( 286 / 2090 )

Copy link

E2E Workflow Workers Coverage Report

Totals Coverage
Statements: 65.43% ( 583 / 891 )
Methods: 59.26% ( 64 / 108 )
Lines: 68.54% ( 464 / 677 )
Branches: 51.89% ( 55 / 106 )

Copy link

E2E Queue Consumers Coverage Report

Totals Coverage
Statements: 81.73% ( 1302 / 1593 )
Methods: 67.51% ( 133 / 197 )
Lines: 84.9% ( 1091 / 1285 )
Branches: 70.27% ( 78 / 111 )

Copy link

E2E SIMS API Coverage Report

Totals Coverage
Statements: 67.4% ( 5922 / 8787 )
Methods: 65.09% ( 729 / 1120 )
Lines: 71.33% ( 4647 / 6515 )
Branches: 47.4% ( 546 / 1152 )

Copy link
Collaborator

@dheepak-aot dheepak-aot left a 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 👍

Copy link
Collaborator

@andrepestana-aot andrepestana-aot left a comment

Choose a reason for hiding this comment

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

Looks good!

@bidyashish bidyashish added this pull request to the merge queue Dec 19, 2024
Merged via the queue into main with commit 60166a6 Dec 19, 2024
21 checks passed
bidyashish added a commit that referenced this pull request Dec 20, 2024
**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)
bidyashish added a commit that referenced this pull request Dec 20, 2024
**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)
@bidyashish bidyashish deleted the feature/#4094-file-comma-issue branch December 20, 2024 00:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants