php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53004 xml parser fails if newline befor the XML-Declaration
Submitted: 2010-10-06 18:29 UTC Modified: 2010-10-06 18:54 UTC
From: php at oshahn dot de Assigned:
Status: Not a bug Package: *XML functions
PHP Version: 5.3.3 OS: Ubuntu 10.10
Private report: No CVE-ID: None
 [2010-10-06 18:29 UTC] php at oshahn dot de
Description:
------------
If there is a newline befor the XML-declaration, the parser fails.
The w3.org only demand:
"The document type declaration MUST appear before the first element in the document."

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

$data = '<?xml version="1.0"?><foo>bar</foo>';

function test($data) {
    print "try to parse: '" . htmlentities($data) . "'<br>\n";
    $parser = xml_parser_create();
    if (!xml_parse($parser, $data)) {
        print "Error: " . xml_error_string(xml_get_error_code($parser)) . "<br>";
        print "Error in Line " . xml_get_current_line_number($parser) . " Column " . xml_get_current_column_number($parser) . "<hr>\n";
    } else {
        print "works fine<hr>";
    }
}
test($data);
test("\n" . $data);


Expected result:
----------------
I expect, that both test succeed.

Actual result:
--------------
Only the first test succeed, the second fails in Line 1 Column 21 "Reserved XML Name".

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-10-06 18:32 UTC] pajoye@php.net
-Status: Open +Status: Bogus
 [2010-10-06 18:32 UTC] pajoye@php.net
Expected, that's part of the XML specifications.
 [2010-10-06 18:40 UTC] php at oshahn dot de
I don't think so.
http://www.w3.org/TR/xml/#sec-prolog-dtd

A newline is not an element.
 [2010-10-06 18:54 UTC] php at oshahn dot de
Ok, I tested it on http://validator.w3.org/

I seems that you are right.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 13 12:01:27 2024 UTC