If in the UI configuration for a field you set a directory for File Field Path that ends with a SLASH such as this one:

paper/[node:nid]/field_version_word/

Paths are generated all over with a double slash, generating random errors in different places, depending on you webserver having a double slash in a path will simply brake access to the file or end up with file permissions errors:

://paper/[node:nid]/field_version_word//xxxxxx.docx

We can blame the user for this, or simply take care of that slash in

filefield_paths_process_string($value, $data, $settings = array())

inside

\sites\all\modules\filefield_paths\modules\filefield_paths.inc

Adding the following line just at the start of the method:

$value = rtrim($value,"/");

I'll be preparing a proper patch in the following days.

And possibly, add some validation in the UI so that the path is checked for "correctness" (I don't know if this is already done, and if it is, add verification for slash at end of directory).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

david_garcia’s picture

Status: Active » Needs review
FileSize
465 bytes
david_garcia’s picture

FileSize
465 bytes

Rerolled against correct branch.

neRok’s picture

Title: Paths are wrongly managed when directory set by user in UI ends with a SLASH » Paths can be set with a SLASH on the end
Status: Needs review » Needs work

Thank you for identifying this issue, which I can confirm does exist. I am not sure your solution is the best though. It would probably be better to check for the slash during the form fields element_validate, as per core (see below).

However, the same check may also be required during filefield_paths_process_string, in case a token adds some slashes.

/**
 * Element validate callback for the file destination field.
 *
 * Remove slashes from the beginning and end of the destination value and ensure
 * that the file directory path is not included at the beginning of the value.
 */
function _file_generic_settings_file_directory_validate($element, &$form_state) {
  // Strip slashes from the beginning and end of $widget['file_directory'].
  $value = trim($element['#value'], '\\/');
  form_set_value($element, $value, $form_state);
}
Deciphered’s picture

Status: Needs work » Fixed

I've implemented the validation callback as per core and it fixes the problem nicely.

I haven't yet dealt with filefield_paths_process_string because I believe there is another issue debating the correct approach to take.

Committed and fixed.

david_garcia’s picture

Thank you @Dechipered! Can you tell us what issue is that?

Deciphered’s picture

Status: Fixed » Closed (fixed)

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