Fix 500 error on dash or space filenames

Created on 30 July 2022, over 2 years ago
Updated 3 November 2023, over 1 year ago

Problem/Motivation

Upload files with dash or space in name causes a 500 error and prevents upload confirm for the whole lot.

Steps to reproduce

Upload any file with a space or a dash in the name.

Proposed resolution

The temporary filename validation regex currently specifies the \w Any word character (letter, number, underscore) selector.

Either, we can:

  1. Change regex to allow dashes, spaces, and other valid filename characters.
  2. Temporarily hack the temporary filename.

Remaining tasks

Determine what other (if any) valid filename characters to include.

Original report by stovak

Just quietly change dashes and spaces in filename to underscores
Many times PLU will error on a simple issue with the filename. Instead of erroring, just quietly rename the file something that is acceptable.

πŸ› Bug report
Status

Postponed: needs info

Version

2.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States stovak Los Angeles

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ͺπŸ‡ΈSpain budalokko Girona

    Could you provide some further instructions to reproduce the error? Maybe there's another module involved.

    Did some tests with both PlUpload and also Plupload Widget on a minimal install but could not reproduce.

    Thank you !!

  • Issue was unassigned.
  • Status changed to Needs work almost 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States jcandan

    Got it. Took some digging, but I found the specific line that is causing a 500 on the temporary file check.

    /**
     * @file src/UploadController.php
     */
    ...
      protected function getFilename() {
        ...
          if (!preg_match('/^\w+\.tmp$/', $this->filename)) {
            throw new UploadException(UploadException::FILENAME_ERROR);
          }
        ..
    

    Filenames with dashes or spaces are not being matched by the \w+.

    I've created a PHP Live Regex permalink for easy testing.

    I am getting this while using the Photos module with its Plupload setting enabled.

    Personally, I think we should go with the option to adjust the regex rather than hack the temporary filename.

    I tried ^[-\s\w]+\.tmp$ in the PHP Live Regex, and it seems like a good fit.

    Any other characters we should account for? Is there some official filename protocol we should shoot for?

  • πŸ‡ΊπŸ‡ΈUnited States jcandan
  • Status changed to Postponed: needs info over 1 year ago
  • πŸ‡ͺπŸ‡ΈSpain budalokko Girona

    Sry did some attempts with the Photos module too, but still can't reproduce.

    In all situations $this->filename at the UploadController::getFilename() method pointed by @jcandan has normal temporary file names in the form o_1h5q7bd49ffi1ps1b10puroh2b.tmp which passes the validation.

    What has to be done so the original file name with spaces or whatever characters reaches this point of the code?

    Maybe in your situations there is some Ajax involved? Which version of the plupload library are you using?

    Setting as "maintainer needs more info" because would like to see the issue before loosening that preg_match.

    Thanks !!

  • πŸ‡¨πŸ‡³China lawxen

    I got the same error,. when using https://www.drupal.org/project/feeds_plupload β†’ , If the file name is chinese, like ζ΅·θ’‚ηš„θŠ±ε›­2号.jpg, error coming

  • πŸ‡ͺπŸ‡ΈSpain budalokko Girona

    As mentioned in #5, at that point of the code `$this->filename` should not contain the original file name but an internal filename in a very specific form: `o_1h5q7bd49ffi1ps1b10puroh2b.tmp`.

    To fix this issue we need to find why in your setups `$this->request->request->get('name')` contains the original file name instead.

    Plupload library seems to already send this file name in the request payload. Can you compare the following screenshots with your situation? Maybe then we can discover why the original file name happens to be there.


    This was with:

    - Drupal 9.5.
    - Plupload 2.1.x at /plupload-test (provided by plupload_test submodule).
    - Plupload library v2.1.9 or v2.3.9 or v3.1.5

Production build 0.71.5 2024