Strip double / prefix when uploading to Media root directory #491
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When uploading to the Media Manager's root directory, the media.file.upload event will prefix the $path variable with two
/
characters. This PR strips the first one.Steps to Replicate:
boot
method:The problem in depth
When uploading to the root directory, the following line produces a path of / because you're uploading to the Media Manager's root directory:
winter/modules/backend/traits/UploadableWidget.php
Line 81 in 86cfbfa
On the very next line we call
validatePath
:winter/modules/backend/traits/UploadableWidget.php
Line 82 in 86cfbfa
which strips the
/
suffix but then adds it back as a prefix:winter/modules/system/classes/MediaLibrary.php
Line 471 in 86cfbfa
and finally on the next line, we add yet another
/
resulting in the behaviour we see in my issue:winter/modules/backend/traits/UploadableWidget.php
Line 83 in 86cfbfa
This should result in uploads to the root directory of the Media Manager having a
$path
of /myimage.jpg as it should.