The task is to change the function to:

function file_stream_wrapper_valid_scheme($scheme) {
  return $scheme && class_exists(file_stream_wrapper_get_class($scheme));
}

and then take these:

346:  if ($scheme && file_stream_wrapper_valid_scheme($scheme)) {
596:  if (empty($uri_scheme) || !file_stream_wrapper_valid_scheme($uri_scheme)) {
1171:  if (!$destination_scheme || !file_stream_wrapper_valid_scheme($destination_scheme)) {
1598:  if ((!$scheme || !file_stream_wrapper_valid_scheme($scheme)) && (substr(PHP_OS, 0, 3) == 'WIN')) {
1671:  if ($scheme && file_stream_wrapper_valid_scheme($scheme)) {
1764:  if ((!$scheme || !file_stream_wrapper_valid_scheme($scheme)) && (substr(PHP_OS, 0, 3) == 'WIN')) {
1800:  if ($scheme && file_stream_wrapper_valid_scheme($scheme)) {

and remove the superflous testing for $scheme, ie make the first if (file_stream_wrapper_valid_scheme($scheme)) {, the second if (!file_stream_wrapper_valid_scheme($uri_scheme)) {

Note that #1874562: Upgrade path broken and yet tests pass adds one more so if it is committed, then that needs to be done too.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

plopesc’s picture

Hello

Attaching patch that rewrites the checking process through the suggested function.

The function is also called from system module. The suferfluous testing has been removed too.

Regards

plopesc’s picture

Status: Active » Needs review

Changing status.

Status: Needs review » Needs work

The last submitted patch, rewrite_checking_schema-1874612-1.patch, failed testing.

plopesc’s picture

Status: Needs work » Needs review
FileSize
4.12 KB

Re-rolling patch. Testing problems should be fixed now.

chx’s picture

Status: Needs review » Reviewed & tested by the community

The reason for test failures were: file_valid_uri and drupal_rmdir had file_stream_wrapper_valid_scheme instead of !file_stream_wrapper_valid_scheme. The patch at this point contains no functional change just simplifies code.

catch’s picture

Title: Simplify file.inc by file_stream_wrapper_valid_scheme(FALSE) return FALSE » Change notice: Simplify file.inc by file_stream_wrapper_valid_scheme(FALSE) return FALSE
Priority: Normal » Critical
Status: Reviewed & tested by the community » Active

Very nice. Could use a small change notice so contrib can remove similar checks.

chx’s picture

Title: Change notice: Simplify file.inc by file_stream_wrapper_valid_scheme(FALSE) return FALSE » Simplify file.inc by file_stream_wrapper_valid_scheme(FALSE) return FALSE
Priority: Critical » Normal
Status: Active » Fixed

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