php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #61542 xml_parse with invalid attribute returns 1; while xmlwf throws an error
Submitted: 2012-03-28 12:21 UTC Modified: 2018-03-14 16:17 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: Sjon at hortensius dot net Assigned: cmb (profile)
Status: Closed Package: XML related
PHP Version: 5.3.10 OS: Archlinux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: Sjon at hortensius dot net
New email:
PHP Version: OS:

 

 [2012-03-28 12:21 UTC] Sjon at hortensius dot net
Description:
------------
Html with an invalid attribute should make xml_parse return 0, instead of 1

For as far as I can see, xml_* is based on expat. Expat supplies xmlwf, so I 
confirmed checked what xmlwf would return for the xml. I found that xmlwf behaves 
correctly.

------

[sjon@sjon-desktop ~]$ xmlwf 
<?xml version="1.0" encoding="UTF-8" ?>
<img src="http://i.mg/" title="a\"b" />
STDIN:2:34: not well-formed (invalid token)


Test script:
---------------
$p = xml_parser_create('UTF-8');
$html = '<img src="http://i.mg/" title="a\"b" />';
var_dump(xml_parse($p, $html));

Expected result:
----------------
0

Actual result:
--------------
1

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-03-14 16:02 UTC] cmb@php.net
-Status: Open +Status: Verified -Type: Bug +Type: Documentation Problem -Assigned To: +Assigned To: cmb
 [2018-03-14 16:02 UTC] cmb@php.net
> For as far as I can see, xml_* is based on expat.

Originally, indeed.  However, it is usually build against libxml2
nowadays.

> Html with an invalid attribute should make xml_parse return 0,
> instead of 1

ACK.  And it does, if you pass TRUE to the $is_final parameter;
otherwise at least the libxml2 based extension still waits for
further input, and does not signal an error.  So the fixed and
enhanced test script would be:

    <?php
    $p = xml_parser_create('UTF-8');
    $html = '<img src="http://i.mg/" title="a\"b" />';
    var_dump(xml_parse($p, $html, true));
    var_dump(xml_error_string(xml_get_error_code($p)));

The actual result will be:

    int(0)
    string(10) "> required"

The documentation[1] already states:

| Entity errors are reported at the end of the data thus only if
| is_final is set and TRUE.

This should be generalized wrt. this issue.

[1] <http://www.php.net/manual/en/function.xml-parse.php#refsect1-function.xml-parse-returnvalues>
 [2018-03-14 16:17 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=344503
Log: Fix #61542: xml_parse with invalid attribute returns 1
 [2018-03-14 16:17 UTC] cmb@php.net
-Status: Verified +Status: Closed
 [2018-03-14 16:17 UTC] cmb@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.
 [2020-02-07 06:05 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=ec7b74c91b675c27e4133d8e79619982bca9806a
Log: Fix #61542: xml_parse with invalid attribute returns 1
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 18:01:28 2024 UTC