If the name of a pagebreak consists only of numbers which are the same as the cid of a component, webform_component_list() returns incorrect results. This happens because webform_component_list() uses pagebreak names as an array key. cid is also used as a key. If both are the same, values will get overwritten.

Comments

Liam Morland created an issue. See original summary.

liam morland’s picture

Status: Active » Needs review
StatusFileSize
new3.36 KB
danchadwick’s picture

Status: Needs review » Needs work

I am pretty sure, but not 100% sure, that the page name (i.e. "label" in the UI) is intended only as a reference to the page. It can be any unique identifier. In this way, the code freely makes them unique by appending "_X" where X is a number.

In the situation you cite, would be possible to still have name conflicts. Suppose you have two identically-named pages "1". The first one would get renamed "1 " (with a space appended). The second one would also get the same name because there is no page name "1" yet in the array being built.

I suggest that the initial attempt for page names always have " " appended, as in:

    if ($pagebreak_groups && $component['type'] == 'pagebreak') {


      // Create a page name which is unique and cannot conflict with a cid.
      $page_name = $component['name'] . ' ';


      $copy = 1;
      while (in_array($page_name, $page_names)) {
        $page_name = $component['name'] . '_' . ++$copy;
      }
      $page_names[$page_num] = $page_name;
    }

What I don't know is which, if any, of the affected calls to webform_component_list with $pagebreak_groups == TRUE could be negatively affected. I would hope none. Conditionals seem okay.

liam morland’s picture

Good point about the space being added before the uniqueness check.

I don't think the space needs to be added except in the rare situations where the name is only digits.

liam morland’s picture

Status: Needs work » Needs review
StatusFileSize
new4.02 KB

This improves the test as well, testing for a page break with the same name as another page break.

liam morland’s picture

With debugging code removed.

  • Liam Morland committed 2032218 on 7.x-4.x
    Issue #2823364: webform_component_list() return value wrong when...
liam morland’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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