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: Media library folders and files can get unintentionally deleted #16759

Merged
merged 8 commits into from May 19, 2023

Conversation

Marc-Roig
Copy link
Contributor

@Marc-Roig Marc-Roig commented May 17, 2023

What does it do?

Delete folder logic was doing something like:

 await strapi.db.query(FILE_MODEL_UID).findMany({
    where: { folderPath: { $startsWith: path } },
  });

And we were missing an edge case. In a list of folder paths like:

/1
/2
/3
/10

If you want to delete /1, and you match by doing { $startsWith: "/1" }, you would get /1 but also /10.

This PR improves the query to prevent this behaviour.

Related issue(s)/PR(s)

Fixes #16734

@Marc-Roig Marc-Roig added source: core:upload Source is core/upload package pr: fix This PR is fixing a bug labels May 17, 2023
@Marc-Roig Marc-Roig self-assigned this May 17, 2023
jhoward1994
jhoward1994 previously approved these changes May 17, 2023
nathan-pichon
nathan-pichon previously approved these changes May 17, 2023
@Marc-Roig Marc-Roig merged commit 1285ba7 into main May 19, 2023
54 checks passed
@Marc-Roig Marc-Roig deleted the fix/delete-unintentional-folders branch May 19, 2023 10:40
@Marc-Roig Marc-Roig added this to the 4.10.6 milestone May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: fix This PR is fixing a bug source: core:upload Source is core/upload package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Media library folders and files can get unintentionally deleted
3 participants