Detection of source and temporary scheme is wrong in filefield_paths_filefield_paths_process_file()

Created on 27 July 2023, 11 months ago
Updated 14 May 2024, about 2 months ago

Problem/Motivation

The function checks that the current stream wrapper of a given file entity is either the temporary or the destination stream wrapper, and if not, it doesn't touch the file.

That makes perfect sense and is exactly what I need in my project. The problem is that the current way of getting the source and temporary stream wrapper is wrong.

I thought this might have been due to the deprecation of related functions in D9/10, but that's not the case. It's been like this since 2015.

What the code does is get a stream wrapper for the given URI, then get its type, which is a description of its features using bitwise constants, and pick the first one of the returned wrappers that has this feature. Because the type works as it does, if you have a read-only remote wrapper that is only implementing READ, then getWrappers() will return pretty much anything, because public for example is also readable. And then it picks public and is happy and proceeds.

Steps to reproduce

Proposed resolution

Use \Drupal\Core\StreamWrapper\StreamWrapperManager::getScheme() to get the scheme directly from the URI

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Closed: duplicate

Version

1.0

Component

Code

Created by

πŸ‡¨πŸ‡­Switzerland Berdir Switzerland

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

Comments & Activities

Production build 0.69.0 2024