php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64126 Regex in XML fails with brackets
Submitted: 2013-02-01 15:31 UTC Modified: 2016-08-28 04:22 UTC
From: pim at highattention dot nl Assigned: cmb (profile)
Status: No Feedback Package: XML related
PHP Version: 5.3.21 OS: CENTOS 6.3 x86_64
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: pim at highattention dot nl
New email:
PHP Version: OS:

 

 [2013-02-01 15:31 UTC] pim at highattention dot nl
Description:
------------
A couple of weeks ago, we upgraded php to 5.3.19. Eversince the following bug 
appears: When I try to get the regex out of a XML file, he only gives the last 
piece as result.

<?xml version="1.0" encoding="utf-8" ?> <simplexml> <regex><![CDATA[/(^[a-zA-Z0-
9._-]+@[a-zA-Z0-9-]+.[a-zA-Z.]{2,5}\$)|^\$/i]]></regex> </simplexml>

The result is ']{2,5}\$)|^\$/i':

> FileHandler_Xml Object
(
    [_filename:protected] => 
    [_parser:protected] => 
    [_children:protected] => Array
        (
            [regex] => FileHandler_Xml_Element Object
                (
                    [_cdata:protected] => ]{2,5}\$)|^\$/i
                    [_attributes:protected] => 
                    [_children:protected] => 
                )
        )
    [obj] => 
)
I use 'XML Parser' to parse the XML to the object above.

I hope somebody can help me out with this problem?

With kind regards,

Pim

Test script:
---------------
public function addXml($xml){

               $this->_parserMemory = array();

        $parser = xml_parser_create( 'UTF-8' );

        

        xml_set_object($parser, $this);

        xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);

        xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);

        xml_set_element_handler($parser, "_xmlTagOpen", "_xmlTagClose");

        xml_set_character_data_handler($parser, "_xmlCdata");

    

        if (!xml_parse($parser, $xml)) {

            $this->_children = array();

            $error_code = xml_get_error_code($parser);

            $error_string = xml_error_string($error_code);

            $current_line = xml_get_current_line_number($parser);

            $current_column = xml_get_current_column_number($parser);


        }

        

        unset($this->_parserMemory);

        xml_parser_free($parser);

}

protected function _xmlCdata($parser, $cdata) 

    {
               
        if ( trim($cdata) != '' && count($this->_parserMemory)>1 ) {

            $obj = $this->getCurrentObject();
            

            $obj->setValue($this->_xmlConvertValueFromString($cdata));
            
            

        }
        


    }

Expected result:
----------------
> FileHandler_Xml Object
(
    [_filename:protected] => 
    [_parser:protected] => 
    [_children:protected] => Array
        (
            [regex] => FileHandler_Xml_Element Object
                (
                    [_cdata:protected] => /(^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+.[a-
zA-Z.]{2,5}\$)|^\$/i
                    [_attributes:protected] => 
                    [_children:protected] => 
                )
        )
    [obj] => 
)

Actual result:
--------------
The result is ']{2,5}\$)|^\$/i':

> FileHandler_Xml Object
(
    [_filename:protected] => 
    [_parser:protected] => 
    [_children:protected] => Array
        (
            [regex] => FileHandler_Xml_Element Object
                (
                    [_cdata:protected] => ]{2,5}\$)|^\$/i
                    [_attributes:protected] => 
                    [_children:protected] => 
                )
        )
    [obj] => 
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-08-17 18:59 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2016-08-17 18:59 UTC] cmb@php.net
I can't reproduce this issue with a simplified test script, see
<https://3v4l.org/4dcOo>.

If this issue still persists for you, please provide a minimal,
but complete and self-contained test script, and further info
about your environment (particularly relevant appear to be PHP
version, the value of XML_SAX_IMPL, and if that's "libxml", the
value of LIBXML_VERSION).
 [2016-08-28 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 21:01:36 2024 UTC