Problem/Motivation

Hi everyone.

First of all this is my first issue report identified at Amsterdam DrupalCon 2014.

In core/includes/install.inc I have identified several unidentified variables in the function drupal_rewrite_settings.
While these variables might(probably) get set through the process of the foreach loop the variables should still have some default values.

This mitigates false positives from static code analysis made by IDE's etc.

The first issue:

        case 'right_bracket':
            if ($value == ']') {
              if (isset($current[$index])) {

The index variable is not set outside the scope and not defined in the case 'right_bracket'.

Second issue:

          case 'candidate_right':
            if (_drupal_rewrite_settings_is_simple($type, $value)) {
              $value = _drupal_rewrite_settings_dump_one($current);
              // Unsetting $current would not affect $settings at all.
              unset($parent[$index]);

Again three variables is used without being defined first or outside the scope of the switch statement.
The three variables are $current, $index and $parent.

The relevant code was moved to \Drupal\Core\Site\SettingsEditor

Steps to reproduce

Proposed resolution

TBA

Remaining tasks

Decide how to correctly define the possibly undefined variables

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Comments

RonnieJ’s picture

StatusFileSize
new528 bytes

This is my first patch.. Hopefully its enough(and good enough).
I simply set the variables to null before the foreach loop. If the loop behaves as expected it should overwrite the variables before used. Otherwise the variables is null.

RonnieJ’s picture

Status: Active » Needs review
jhedstrom’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Patch still applies, and this makes sense to set defaults for these variables. I've added a beta phase evaluation to the issue summary.

jhedstrom’s picture

Issue summary: View changes
jhedstrom’s picture

Status: Reviewed & tested by the community » Needs work

Actually, the patch needs to be updated to meet coding standards. The 'nulls' should be all upper case, or perhaps be set to 0 since they are used as integers.

sushantpaste’s picture

StatusFileSize
new525 bytes

Updated patch.

sushantpaste’s picture

Status: Needs work » Needs review

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

quietone’s picture

Status: Needs review » Reviewed & tested by the community

I agree with the comment in #3 that having defaults make sense. The patch still applies and tests pass on 8.5 and 8.6

alexpott’s picture

Status: Reviewed & tested by the community » Needs review

I'm not sure. Setting the values might hide useful errors. In the current design you should never use these variables before they are assigned. If it happens then you get a useful warning telling you that's what has happened. With this change that would go away. Ideally drupal_rewrite_settings() would be redesigned to be easier to bugfix and have less complexity.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Novice

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

Still seems to be relevant but the bulk of the code was moved to SettingsEditor.php

Tagged for novice for beginner developers.

_utsavsharma’s picture

StatusFileSize
new621 bytes

Patch for 10.1.x.

Aadhar_Gupta’s picture

Status: Needs work » Needs review
StatusFileSize
new21.46 KB
new21.47 KB

Applying fix for 10.1.x and fixing custom commands

smustgrave’s picture

Status: Needs review » Needs work

Not sure what happened but that patch is full of out of scope changes. Can compare the files sizes between the two and see

quietone’s picture

Status: Needs work » Active
Issue tags: -Novice

According to #14, this is not a novice issue. I am removing the tag. Setting to active since this needs a re-think.

alexpott’s picture

Category: Bug report » Task
Issue tags: +Needs issue summary update

We also need a new issue summary and title given this now has nothing to do with install.inc

I think rather than focussing on the unused variables we should focus on the design of \Drupal\Core\Site\SettingsEditor and see if we can improve that. And as part of that solve the "variable might not be defined" warnings in the class.

Also this really is a task and not a bug.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Title: Undefined varibles in install.inc » Undefined varibles in \Drupal\Core\Site\SettingsEditor
Assigned: RonnieJ » Unassigned
Issue summary: View changes
Issue tags: -Needs issue summary update

#3244570

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.