Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
On a windows server (in my case IIS8), when you upload new files or use the retroactive update, you get paths with back slashes in the managed files database tables.
Comment | File | Size | Author |
---|---|---|---|
#26 | 2858308-fix-windows-backslash.patch | 1.21 KB | xandeadx |
#23 | after-patch-14.png | 30.14 KB | chrisck |
#23 | before-patch-14.png | 33.39 KB | chrisck |
#21 | interdiff_7-21.txt | 1.21 KB | chrisck |
#21 | fix-windows-backslash_2858308_21.patch | 1.21 KB | chrisck |
|
Issue fork filefield_paths-2858308
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
rooby CreditAttribution: rooby commentedComment #3
rooby CreditAttribution: rooby commentedComment #4
Stephane Boro CreditAttribution: Stephane Boro commentedI may have found a solution to this particular problem. In filefield_paths.inc, I replaced the following line (#101) :
$destination = file_stream_wrapper_uri_normalize($field_storage->getSetting('uri_scheme') . '://' . $path . DIRECTORY_SEPARATOR . $name);
By this :
$destination = file_stream_wrapper_uri_normalize($field_storage->getSetting('uri_scheme') . '://' . $path . '/' . $name);
I just replaced DIRECTORY_SEPARATOR by '/' and it solved the problem for me.
Comment #5
WorldFallz CreditAttribution: WorldFallz commentedJust ran into this same issue. And while #4 fixes it, I don't think that's the right thing to do. DIRECTORY_SEPARATOR is the correct use there, but then it becomes why is core not sending the rest of the url with the correct separator. I'll do some spelunking and see if I can figure out where/what needs patching.
Comment #6
WorldFallz CreditAttribution: WorldFallz commentedIn the meantime, for better site patch management, patch for #4 attached.
Comment #7
rivimeyThis boils down to the definition of a URL:
A URL always uses "/" for separators even when the native file system uses "\". So a WIndows file URL would be: "file:///Users/public/Desktop" while it's native file path might be "C:\Users\public\Desktop"
When the DB is storing URL or URI, then "/" is always correct.
When the DB is storing an native file path, then DIRECTORY_SEPARATOR is correct.
Comment #8
WorldFallz CreditAttribution: WorldFallz commentedThanks for that clarification rivi-- makes perfect sense.
So it seems like DIRECTORY_SEPARATOR in the context of a file URI is actually incorrect, right?
Comment #9
rivimeyI believe so.
Wikipedia is fairly defininte on the subject, anyway: https://en.wikipedia.org/wiki/URL#Syntax
Comment #10
Bohus UlrychHi, just tested on my Windows installation and I think that it is 100% true what @rivimey said.
In database table file_managed are stored URIs - so doesn't matter what OS you are running - it should be always "/"
Note: Windows are often used by beginners and they will have problem to solve this themselves. IMHO this should be fixed ASAP.
Thanks
Comment #11
EricVL CreditAttribution: EricVL commentedThe patch in #6 is only for beta1 release.
Because this issue is not implemented in the latest beta2 release and the filefield_paths.inc file is changed for other reasons, the patch in #6 should be adapted so that the DIRECTORY_SEPARATOR is changed by '/' again.
(the linenumber is changed from 101 to 102 and the function that used this parameter is changed too)
Greetings,
Eric
Sorry to you all.
I have compared the wrong versions although the fix is still not done. The fix in #6 is still valid for the beta2 version.
There should be another patch with the next release because it does not work on the latest version on the dev branch.
Comment #12
jay.lee.bio CreditAttribution: jay.lee.bio commentedThanks, this issue drove me nuts for a few hours. #6 works for 8.x-1.0-beta2 on Drupal 8.8.5, Wampserver 3.2.0.
Comment #13
DrupalDope CreditAttribution: DrupalDope commentedsame here!
thanks for that #6 fix
Comment #14
WorldFallz CreditAttribution: WorldFallz commentedUpdated patch for beta2. I think this should be fixed before release.
Comment #15
EricVL CreditAttribution: EricVL commentedWhat a pitty that this issue is not solved in the beta5 release.
The only thing to do is replacing a constant (DIRECTORY_SEPARATOR) by a character (/).
Next time maybe??
Comment #16
EricVL CreditAttribution: EricVL commentedThis is the patch for the beta5 version. Do use it and try out.
Comment #17
kumkum29 CreditAttribution: kumkum29 commentedHi EricVL,
your patch don't work on beta5 version (The line is 102 not 99).
Thanks.
Comment #18
EricVL CreditAttribution: EricVL commented@kumkum29 Thank you for your remark. Probably my reference was wrong.
Anyway, the patch works and should be included in a new release.
Greetings
Comment #19
tobiberlinThis patch from #16 solved the issue as described here https://www.drupal.org/project/filefield_paths/issues/2827652 for me. I work on a Windows PC with WAMP installed
Comment #20
chrisck CreditAttribution: chrisck commentedNeeds reroll for dev
Comment #21
chrisck CreditAttribution: chrisck commentedRerolled patch for 8.x-1.x-dev. This is my first patch. Found DIRECTORY_SEPARATOR in /src/Redirect.php and made the change to '/'. The backslashes in file paths are now gone as seen in /admin/config/search/redirect however the redirect creation is not correct, it's showing new path redirecting to new path.
Comment #22
EricVL CreditAttribution: EricVL commented@chrisck. You should not change the DIRECTORY_SEPARATOR definition by a / everywhere you find a DIRECTORY_SEPARATOR.
DIRECTORY_SEPARATOR translates to a \ in windows and to a / in unix. It should only be used in a specification of a path in a file system and not in a URL. In a URL the separator is always a /.
In the Redirect.php file in the function getPath() this returns a path to a file. In that case, one should use DIRECTORY_SEPARATOR.
Greetings
Eric
Comment #23
chrisck CreditAttribution: chrisck commented@EricVL thanks for your reply. In the redirect table on this page /admin/config/search/redirect the path is a URL and is incorrectly showing backslashes (see before-patch.png). The link is also broken in the second column.
After applying my patch #21 the backslashes in the URL path are changed into forward slashes and is showing a correct URL structure (see after-patch.png).
Before patch
After patch
What still needs to be fixed is the "From" path (i.e. source/old path) is not correct. It is incorrectly showing the new path.
Comment #24
EricVL CreditAttribution: EricVL commented@chrisck : sorry for my remark but I don't use the Redirect module and therefor was unable to test this.
Comment #25
chrisck CreditAttribution: chrisck commentedComment #26
xandeadx CreditAttribution: xandeadx commentedSorry, it's same. Please delete comment.
Comment #27
winkflo CreditAttribution: winkflo commentedThanks to EricVL,
the patch #16 works for me. I am on Drupal 9.4.x and filefield_path Version: 8.x-1.0-beta5. Developing on a Windows machine using Laragon, Apache and MySQL.
I hope this will be included in the next release. I don't want to miss the great module filefield_path in any of my Drupal projects.
Comment #32
volegerThanks for the patch. It allows passing one of the failing tests. Thanks