Random validation errors on file upload

Created on 8 February 2022, over 2 years ago
Updated 13 January 2024, 6 months ago
</code><h3 id="summary-problem-motivation">Problem/Motivation</h3>
Occasionally, on file upload action, the following validation error is occurring for file field: "This value should not be null". 

We have a pretty straightforward setup:
1) Media type with "File" field;
2) "PLupload widget" is selected in Manage Form display;
3) There are no other file fields and customizations;

My investigation led me to the following lines in <code>FileWidget::value()

method:

// If a unique identifier added with '--', we need to exclude it.
if (preg_match('/(.*)(--[0-9A-Za-z-]+)$/', $id, $reg)) {
  $id = $reg[1];
}

It turns out that element id may contain also underscore (_), which is not covered here. In such cases, ID can't be determined and the whole process fails.

Underscore is possible due to Drupal\Component\Utility::randomBytesBase64(), which is used in Drupal\Component\Html::getUniqueId().

Steps to reproduce

It might be hard to reproduce due to the bug source. Try to upload files until you hit this error. It's not required to submit a form, you just need to trigger "upload" process. Occurrence is approximately 2/ 10. I think it was easier to reproduce after clearing the cache.

Proposed resolution

I'm not sure if only underscore is missing. We should opdate a regular expression to cover all possible variations.

Remaining tasks

  • Make sure all cases are covered in the merge request;
  • Commit
πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡¦Ukraine Matroskeen πŸ‡ΊπŸ‡¦ Ukraine, Lutsk

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

Merge Requests

Comments & Activities

Not all content is available!

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

Production build 0.69.0 2024