php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #51939 Add xml_set_entity_decl_handler function
Submitted: 2010-05-28 01:40 UTC Modified: 2017-10-24 07:11 UTC
Votes:6
Avg. Score:3.5 ± 0.8
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:2 (66.7%)
From: mchenryc at gmail dot com Assigned:
Status: Open Package: XML related
PHP Version: trunk-SVN-2010-05-28 (SVN) OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mchenryc at gmail dot com
New email:
PHP Version: OS:

 

 [2010-05-28 01:40 UTC] mchenryc at gmail dot com
Description:
------------
When parsing XML, PHP has no way to set a handler for general entities, though a 
handler can be set for unparsed entities.

Expat has deprecated the XML_SetUnparsedEntityDeclHandler in favor of 
XML_SetEntityDeclHandler, which is called for all entity types (including general 
and unparsed).

http://expat.cvs.sourceforge.net/viewvc/expat/expat/lib/expat.h?
revision=1.80&view=markup#l_311

PHP should add the xml_set_entity_decl_handler function to allow handling of all 
entity declarations.


Test script:
---------------
$data = '<!DOCTYPE test [<!ENTITY generalEntity "General Entity">]><test>&generalEntity;</test>';

function h_entity_decl($parser,$entity_name,$is_parameter_entity,$value,$base,$system_id,$public_id,$notation_name) {
	echo "$entity_name - $is_parameter_entity - $value";
};

$parser = xml_parser_create();
xml_set_entity_decl_handler($parser, 'h_entity_decl');

xml_parse($parser,$data,false) or 
    die (sprintf("XML Error: %s at line %d<br>\n", 
				 xml_error_string(xml_get_error_code($parser)),
				 xml_get_current_line_number($parser)));
xml_parser_free($parser);


Expected result:
----------------
It should run with the following output:

generalEntity - 0 - General Entity


Actual result:
--------------
Fatal Error: Call to undefined function xml_set_entity_decl_handler()


Patches

Bug51939.patch (last revision 2011-07-21 13:03 UTC by davidc@php.net)
bug51939-3-ws.patch (last revision 2011-07-21 12:43 UTC by davidc@php.net)
bug51392-ws (last revision 2011-07-21 12:39 UTC by davidc@php.net)
bug51939.patch (last revision 2011-07-19 16:21 UTC by davidc@php.net)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-15 07:23 UTC] davidc@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: davidc
 [2011-07-19 12:21 UTC] davidc@php.net
The following patch has been added/updated:

Patch Name: bug51939.patch
Revision:   1311092480
URL:        https://bugs.php.net/patch-display.php?bug=51939&patch=bug51939.patch&revision=1311092480
 [2011-07-19 12:22 UTC] davidc@php.net
I've added a patch for this but I'd like to write a few more tests before committing it. If you could apply it and let me know if this helps you that'd be 
nice.
 [2011-07-21 08:39 UTC] davidc@php.net
The following patch has been added/updated:

Patch Name: bug51392-ws
Revision:   1311251978
URL:        https://bugs.php.net/patch-display.php?bug=51939&patch=bug51392-ws&revision=1311251978
 [2011-07-21 08:43 UTC] davidc@php.net
The following patch has been added/updated:

Patch Name: bug51939-3-ws.patch
Revision:   1311252230
URL:        https://bugs.php.net/patch-display.php?bug=51939&patch=bug51939-3-ws.patch&revision=1311252230
 [2011-07-21 09:03 UTC] davidc@php.net
The following patch has been added/updated:

Patch Name: Bug51939.patch
Revision:   1311253426
URL:        https://bugs.php.net/patch-display.php?bug=51939&patch=Bug51939.patch&revision=1311253426
 [2016-02-15 00:45 UTC] anrdaemon at freemail dot ru
Just fell for this trap by myself.
Internal entity declarations are not handled, and fall into default handler or produce errors altogether, depends on your parser setup.
 [2016-02-15 03:18 UTC] anrdaemon at freemail dot ru
David, instead of adding "xml_set_entity_decl_handler" as a new function, how about making it an alias to xml_set_unparsed_entity_decl_handler (or, more precisely, the other way around), and call xml_set_entity_decl_handler() with $system_id set to entity value for internal entities?
 [2017-10-24 07:11 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: davidc +Assigned To:
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 18:01:29 2024 UTC