Uploaded image for project: 'eZ Publish / Platform'
  1. eZ Publish / Platform
  2. EZP-8427

elementByAttributeValue destroys Children array, in eZDOMNode - patch included

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Medium
    • Resolution: Fixed
    • Affects Version/s: 3.7.5
    • Fix Version/s: 3.10.0beta1, 3.8.9, 3.9.3, 4.0.0alpha1
    • Component/s: Misc
    • Labels:
      None
    • Environment:

      Version: 3.7.5
      PHP Version: 4.4.2
      Webserver: Apache 1.3
      Database: MySQL

      Description

      There is a bug in eZDOMNode::elementByAttributeValue that makes it destroy the last element in the Children array when there are no matches.

      I was trying to build an XML document without duplicate elements, but ended up with an error message:

      Fatal error: Call to a member function on a non-object in /var/www/vhosts/arkivplan/html/lib/ezxml/classes/ezdomnode.php on line 429

      Code to reproduce:

      require_once('lib/ezxml/classes/ezxml.php');
      $doc=&new eZDOMDocument('Document');
      $node=&$doc->createElementNode('RootNode');
      $doc->setRoot($node);
      foreach(array('A','B','C') as $attrib) {
      if ($node->elementByAttributeValue('attr',$attrib)===false)

      { $node->appendChild($doc->createElementNode('SubNode',array('attr'=>$attrib))); }

      }

      This will cause the abovementioned error on the third iteration.

      The problem is that the function loops through the children by reference, then when no element is found, the same variable is set to false(not by reference), thus overwriting the value in the array. My simplest solution is to use a different variable name, see attached patch.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                dl Dmitry Lakhtyuk
                Reporter:
                edorfaus Frode Austvik
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: