php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31821 XML parse error not reported
Submitted: 2005-02-02 22:20 UTC Modified: 2005-02-13 22:30 UTC
From: jsmestad at advantageline dot com Assigned:
Status: Closed Package: *XML functions
PHP Version: 5CVS-2005-02-02 (dev) OS: Windows XP Professional SP2
Private report: No CVE-ID: None
 [2005-02-02 22:20 UTC] jsmestad at advantageline dot com
Description:
------------
The XML parser does not return an error when expected.

Reproduce code:
---------------
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startTag", "endTag");
xml_set_character_data_handler($xml_parser, "cdata");
$data = xml_parse($xml_parser,"<thdoc><this>this&that</this><that>thatdata</that></thdoc>");
printf("%s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser));


Expected result:
----------------
not well-formed (invalid token) at line 1

Actual result:
--------------
No error at line 1

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-02-04 14:21 UTC] rrichards@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

you need to set is_final flag for the error to appear when using libxml rather than expat so that libxml knows that all the data has been passed to the parser:
xml_parse($xml_parser,"<thdoc><this>this&that</this><that>thatdata</that></thdoc>", TRUE);
 [2005-02-04 15:18 UTC] jsmestad at advantageline dot com
The documentation does not make the behavior of the parser obvious. It states this:

"
When the XML document is parsed, the handlers for the configured events are called as many times as necessary, after which this function returns TRUE or FALSE. 

TRUE is returned if the parse was successful, FALSE if it was not successful, or if parser does not refer to a valid parser. For unsuccessful parses, error information can be retrieved with xml_get_error_code(), xml_error_string(), xml_get_current_line_number(), xml_get_current_column_number() and xml_get_current_byte_index(). 
"

For that string of XML, the parse was unsuccessful, and yet that particular call to xml_parse returns true. This behavior is contrary to the documentation. It states, and I repeat, "TRUE is returned if the parse was successful, FALSE if it was not successful, or if parser does not refer to a valid parser." Yet, true is returned also if the parse is unsuccessful and not specified as complete by the is_final flag.
 [2005-02-07 21:43 UTC] jsmestad at advantageline dot com
As stated, I believe this to be a documentation problem.
 [2005-02-13 22:30 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2005-02-13 22:30 UTC] vrana@php.net
Fixed by: "Entity errors are reported at the end of the data thus only if is_final is set and TRUE."
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Jan 17 23:01:23 2020 UTC