Hello!

I just stumbled upon this bug so I am gonna document it for the time being. Later on I will return and will put a patch here.

Steps to reproduce:

  1. Add a webform with element "managed_file" on it. In the configs of the managed_file element make sure to enable the "Sanitize file name" checkbox.
  2. Go and submit a webform, upload arbitrary file with the name "this-last-t-is-cut.txt".
  3. Go and see the webform submission. Observe the file name to be "this-last-t-is-cu.txt" though the expected result is to have it under the name "this-last-t-is-cut.txt".

The problem is the rtrim(pathinfo($destination_filename, PATHINFO_BASENAME), ".$destination_extension") because rtrim trims on character-level, not a substring. So we tell PHP to trim all of the ., t, x characters from the right. So it cuts the extension + the t char in the file name.

Personally I do not think we need a test to cover this, but if others insist, I can write a test the pinpoints the bug.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bucefal91 created an issue. See original summary.

jrockowitz’s picture

It is fine to not to include test coverage for a basic fix that just makes sense. If we keep having problems with sanitizing filenames we can write some tests.

bucefal91’s picture

Status: Active » Needs review
FileSize
1.04 KB

here comes the easy fruit :) I will commit it if test bot likes it.

jrockowitz’s picture

Status: Needs review » Reviewed & tested by the community

Looks good.

  • bucefal91 committed e40e529 on 8.x-5.x
    Issue #2942174 by bucefal91: Fixing how file extension is stripped in...
bucefal91’s picture

Status: Reviewed & tested by the community » Fixed

Fixed :)

Status: Fixed » Closed (fixed)

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