php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18033 Leading white space is lost inside processing-instruction data
Submitted: 2002-06-27 20:54 UTC Modified: 2003-08-09 15:04 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: gk at proliberty dot com Assigned:
Status: Not a bug Package: XML related
PHP Version: 4.3.3RC2-dev 5.0.0b2 OS: linux 2.4.18
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
24 + 19 = ?
Subscribe to this entry?

 
 [2002-06-27 20:54 UTC] gk at proliberty dot com
<?php
/* 
BUG in PHP 4.2.1:
Leading white space is lost inside processing-instruction data, prior to first character after pi-target

output is:
bug
    php 4.2.1
bugpi_data=hello
end_pi_data

output SHOULD be:
bug
    php 4.2.1
bug

pi_data=
    hello
end_pi_data

*/

/// CODE TO REPRODUCE BUG

$q = '?';
$xmlSource = <<< EOD
<{$q}xml version="1.0"{$q}>
<bug>
    php 4.2.1
</bug>

<{$q}php
    hello
{$q}>
EOD;

$parser = xml_parser_create(); 
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); 
// this doesn't do anything:
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0); 
xml_set_element_handler($parser, "start_element", "stop_element"); 
xml_set_character_data_handler($parser, "char_data"); 
xml_set_processing_instruction_handler( $parser, "_handlePI");
xml_parse( $parser, $xmlSource );

function _handlePI($parser, $target, $data) {
    echo("pi_data=".$data."end_pi_data"); exit;
}

function start_element($parser, $data, $attribs) {
echo $data;
}
function stop_element($parser, $data ) {
echo $data;

}
function char_data($parser, $data ) {
echo $data;
}
?>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-10-16 15:25 UTC] iliaa@php.net
There is another issue here that I've come across while testing the bug. If the variable containing the XML data contains any white space such as \n, \r or ' ', the resulting output is blank.
 [2003-08-09 15:04 UTC] rrichards@php.net
Whitespace after the target are removed - normal behavior.
The linespacing (between the closing bug tag and the PI) is screwed up as your xml is not well formed.

As far as whitespaces in the variable producing blank output, check the return error. The xml declaration is probably screwed up to produce no output. This was the only instance I could reproduce no output.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 19:01:29 2024 UTC