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
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: php at oshahn dot de
New email:
PHP Version: OS:

 

 [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

Add a Patch

Pull Requests

Add a Pull Request

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: Wed Apr 24 14:01:30 2024 UTC