php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52987 Losing amperstamp with xml_parse_into_struct function
Submitted: 2010-10-04 22:05 UTC Modified: 2013-02-18 00:34 UTC
Votes:3
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: andre dot boily at mcccf dot gouv dot qc dot ca Assigned:
Status: No Feedback Package: XML related
PHP Version: 5.2.14 OS: Linux - SUSE
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2010-10-04 22:05 UTC] andre dot boily at mcccf dot gouv dot qc dot ca
Description:
------------
Running version: 5.2.14

After a lot of tests and reading, I experimenting a problem since we've upgraded the PHP version from 5.2.6 to 5.2.14

The problem is when i'm trying to put a xml string in a array, i'm loosing the amperstamp (&)characters in the output of xml_parse_into_struct function.

Maybe it's a new features that I can't understand, but it look like a Bug.

Note: The Bug is in the URL tag in my XML structure.

Test script:
---------------
<?php

$xmlValues  = array();
$xmlIndex   = array();

$parser     = xml_parser_create("");

// Case management option
xml_parser_set_option(
$parser,
XML_OPTION_CASE_FOLDING,
1
);
        
// White space management option
xml_parser_set_option(
$parser,
XML_OPTION_SKIP_WHITE,
            0
);
		
xml_parser_set_option(
$parser,
XML_OPTION_TARGET_ENCODING,
"UTF-8"
);



$data = "<?xml version='1.0' encoding='utf-8'?><COLLECTION><DOCUMENT><TITRE>Some Title</TITRE><URL>http://www.test.com?param1=1&amp;param2=2</URL><DATE>1285352820</DATE></DOCUMENT></COLLECTION>";

xml_parse_into_struct(
            $parser,
            $data,
            $xmlValues,
            $xmlIndex
        );
		
var_dump($xmlValues);

?>

Expected result:
----------------
array(6) { [0]=>  array(3) { ["tag"]=>  string(10) "COLLECTION" ["type"]=>  string(4) "open" ["level"]=>  int(1) } [1]=>  array(3) { ["tag"]=>  string(8) "DOCUMENT" ["type"]=>  string(4) "open" ["level"]=>  int(2) } [2]=>  array(4) { ["tag"]=>  string(5) "TITRE" ["type"]=>  string(8) "complete" ["level"]=>  int(3) ["value"]=>  string(10) "Some Title" } [3]=>  array(4) { ["tag"]=>  string(3) "URL" ["type"]=>  string(8) "complete" ["level"]=>  int(3) ["value"]=>  string(36) "http://www.test.com?param1=1&amp;param2=2" } [4]=>  array(3) { ["tag"]=>  string(8) "DOCUMENT" ["type"]=>  string(5) "close" ["level"]=>  int(2) } [5]=>  array(3) { ["tag"]=>  string(10) "COLLECTION" ["type"]=>  string(5) "close" ["level"]=>  int(1) } } 

Actual result:
--------------
array(6) { [0]=>  array(3) { ["tag"]=>  string(10) "COLLECTION" ["type"]=>  string(4) "open" ["level"]=>  int(1) } [1]=>  array(3) { ["tag"]=>  string(8) "DOCUMENT" ["type"]=>  string(4) "open" ["level"]=>  int(2) } [2]=>  array(4) { ["tag"]=>  string(5) "TITRE" ["type"]=>  string(8) "complete" ["level"]=>  int(3) ["value"]=>  string(10) "Some Title" } [3]=>  array(4) { ["tag"]=>  string(3) "URL" ["type"]=>  string(8) "complete" ["level"]=>  int(3) ["value"]=>  string(36) "http://www.test.com?param1=1param2=2" } [4]=>  array(3) { ["tag"]=>  string(8) "DOCUMENT" ["type"]=>  string(5) "close" ["level"]=>  int(2) } [5]=>  array(3) { ["tag"]=>  string(10) "COLLECTION" ["type"]=>  string(5) "close" ["level"]=>  int(1) } } 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-10-07 04:13 UTC] aharvey@php.net
-Status: Open +Status: Feedback -Package: Systems problem +Package: XML related
 [2010-10-07 04:13 UTC] aharvey@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/

Works as expected for me on a current 5.2 build: the relevant bit of
output is:


  [3]=>
  array(4) {
    ["tag"]=>
    string(3) "URL"
    ["type"]=>
    string(8) "complete"
    ["level"]=>
    int(3)
    ["value"]=>
    string(37) "http://www.test.com?param1=1&param2=2"
  }

Note the decoded ampersand in the value.
 [2010-10-18 21:47 UTC] andre dot boily at mcccf dot gouv dot qc dot ca
I saw in the snapshot you've send me, the BUG is corrected in version 2.5.15.


- Fixed bug #45996 (libxml2 2.7 causes breakage with character data in
  xml_parse()). (Rob)

Thanx!
 [2013-02-18 00:34 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 "Open". Thank you.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon Sep 16 22:01:27 2019 UTC