Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rooby created an issue. See original summary.

rooby’s picture

Issue summary: View changes
rooby’s picture

Priority: Normal » Major
Stephane Boro’s picture

I 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.

WorldFallz’s picture

Just 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.

WorldFallz’s picture

In the meantime, for better site patch management, patch for #4 attached.

rivimey’s picture

This 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.

WorldFallz’s picture

Thanks for that clarification rivi-- makes perfect sense.

So it seems like DIRECTORY_SEPARATOR in the context of a file URI is actually incorrect, right?

rivimey’s picture

I believe so.

Wikipedia is fairly defininte on the subject, anyway: https://en.wikipedia.org/wiki/URL#Syntax

Bohus Ulrych’s picture

Hi, 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

EricVL’s picture

The 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.

jay.lee.bio’s picture

Thanks, 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.

DrupalDope’s picture

same here!
thanks for that #6 fix

WorldFallz’s picture

Updated patch for beta2. I think this should be fixed before release.

EricVL’s picture

What 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??

EricVL’s picture

This is the patch for the beta5 version. Do use it and try out.

kumkum29’s picture

Hi EricVL,

your patch don't work on beta5 version (The line is 102 not 99).

Thanks.

EricVL’s picture

@kumkum29 Thank you for your remark. Probably my reference was wrong.
Anyway, the patch works and should be included in a new release.
Greetings

tobiberlin’s picture

This 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

chrisck’s picture

Issue tags: +Needs reroll

Needs reroll for dev

chrisck’s picture

Rerolled 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.

EricVL’s picture

@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

chrisck’s picture

FileSize
33.39 KB
30.14 KB

@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
fix windows backslash before patch

After patch
fix windows backslash 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.

EricVL’s picture

@chrisck : sorry for my remark but I don't use the Redirect module and therefor was unable to test this.

chrisck’s picture

Issue tags: -Needs reroll
xandeadx’s picture

Sorry, it's same. Please delete comment.

winkflo’s picture

Thanks 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.

Status: Needs review » Needs work

The last submitted patch, 26: 2858308-fix-windows-backslash.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

voleger made their first commit to this issue’s fork.

  • voleger committed 293ad61 on 8.x-1.x
    Issue #2858308 by WorldFallz, voleger, chrisck, EricVL, xandeadx: File...
voleger’s picture

Status: Needs work » Fixed

Thanks for the patch. It allows passing one of the failing tests. Thanks

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.