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: make extension patterns match the end of the file name #5652

Conversation

ugur-vaadin
Copy link
Contributor

Description

Currently, the extensions that contain multiple dots (like .tar.gz) are rejected by Upload even if the extension is provided through they should be accepted. This PR changes the way the matchers work. The current approach is extracting an extension from a file name and searching for exact matches. With the changes, it will be checked whether the file name ends with one of the provided extensions.

Fixes #4777

Type of change

  • Bugfix
  • Feature

Checklist

  • I have read the contribution guide: https://vaadin.com/docs/latest/contributing/overview
  • I have added a description following the guideline.
  • The issue is created in the corresponding repository and I have referenced it.
  • I have added tests to ensure my change is effective and works as intended.
  • New and existing tests are passing locally with my change.
  • I have performed self-review and corrected misspellings.

@DManstrator
Copy link

With the changes, it will be checked whether the file name ends with one of the provided extensions.

Does that mean that if .tar.gz is an accepted file type, that .gz files are also allowed? Not sure if that should be the case.

@ugur-vaadin
Copy link
Contributor Author

With the changes, it will be checked whether the file name ends with one of the provided extensions.

Does that mean that if .tar.gz is an accepted file type, that .gz files are also allowed? Not sure if that should be the case.

If .tar.gz is the only accepted file type, .gz files will be rejected. .gz will have to be explicitly added to the accepted file types. However, if .gz is the only accepted file type, .tar.gz files will also be allowed.

Co-authored-by: Sergey Vinogradov <mr.vursen@gmail.com>
packages/upload/src/vaadin-upload.js Outdated Show resolved Hide resolved
packages/upload/src/vaadin-upload.js Outdated Show resolved Hide resolved
@DManstrator
Copy link

If .tar.gz is the only accepted file type, .gz files will be rejected. .gz will have to be explicitly added to the accepted file types. However, if .gz is the only accepted file type, .tar.gz files will also be allowed.

Then I simply misread your description, sorry. Thank you for the explanation and the added test!

Co-authored-by: Sergey Vinogradov <mr.vursen@gmail.com>
packages/upload/src/vaadin-upload.js Outdated Show resolved Hide resolved
packages/upload/src/vaadin-upload.js Outdated Show resolved Hide resolved
@ugur-vaadin ugur-vaadin removed the request for review from yuriy-fix March 13, 2023 08:50
@sonarcloud
Copy link

sonarcloud bot commented Mar 13, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

vaadin-bot pushed a commit that referenced this pull request Mar 13, 2023
* fix: make extension patterns match the end of the file name

* fix: make the regex safari-compatible

* refactor: remove extra lines

* refactor: update naming for clarification

* refactor: rename file name and extension in test

* Update packages/upload/test/adding-files.test.js

Co-authored-by: Sergey Vinogradov <mr.vursen@gmail.com>

* test: add a test for rejecting files that have partial extension match

* refactor: extract regex logic in a loop and make it a function

* Update packages/upload/src/vaadin-upload.js

Co-authored-by: Sergey Vinogradov <mr.vursen@gmail.com>

* refactor: change the call in order to align with the naming change

* fix: return null instead of undefined

---------

Co-authored-by: Sergey Vinogradov <mr.vursen@gmail.com>
@vaadin-bot
Copy link
Collaborator

Hi @ugur-vaadin , this commit cannot be picked to 23.3 by this bot, can you take a look and pick it manually?
Error Message: Error: Command failed: git cherry-pick 6a6832c
error: could not apply 6a6832c... fix: make extension patterns match the end of the file name (#5652)
hint: After resolving the conflicts, mark them with
hint: "git add/rm ", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".

@vaadin-bot
Copy link
Collaborator

Hi @ugur-vaadin , this commit cannot be picked to 23.2 by this bot, can you take a look and pick it manually?
Error Message: Error: Command failed: git cherry-pick 6a6832c
error: could not apply 6a6832c... fix: make extension patterns match the end of the file name (#5652)
hint: After resolving the conflicts, mark them with
hint: "git add/rm ", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".

ugur-vaadin added a commit that referenced this pull request Mar 13, 2023
…5660)

* fix: make extension patterns match the end of the file name

* fix: make the regex safari-compatible

* refactor: remove extra lines

* refactor: update naming for clarification

* refactor: rename file name and extension in test

* Update packages/upload/test/adding-files.test.js



* test: add a test for rejecting files that have partial extension match

* refactor: extract regex logic in a loop and make it a function

* Update packages/upload/src/vaadin-upload.js



* refactor: change the call in order to align with the naming change

* fix: return null instead of undefined

---------

Co-authored-by: Ugur Saglam <106508695+ugur-vaadin@users.noreply.github.com>
Co-authored-by: Sergey Vinogradov <mr.vursen@gmail.com>
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.

None yet

4 participants