Bug #74988 [NEW]: DOMDocument::load() reports success but libxml_get_errors() return errors

From: Date: Tue, 25 Jul 2017 21:09:54 +0000
Subject: Bug #74988 [NEW]: DOMDocument::load() reports success but libxml_get_errors() return errors
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-210326@lists.php.net to get a copy of this message
From: paul at sparrowhawkcomputing dot com Operating system: Windows 10 Pro PHP version: 5.6.31 Package: DOM XML related Bug Type: Bug Bug description:DOMDocument::load() reports success but libxml_get_errors() return errors Description: ------------ Given the following XML document in test.xml: <?xml version="1.0"?> <root xml:space='foo'/> The script in the "Test Script" field below reports that the instance is loaded successfully while simultaneously reporting well-formedness errors. How can this instance be successfully loaded while there are well-formedness errors reported? Test script: --------------- libxml_use_internal_errors( true ); $dom = new DOMDocument(); libxml_clear_errors(); $success = $dom->load( __DIR__ . '/test.xml' ); $xml = $dom->saveXML(); $errs = libxml_get_errors(); var_dump( $success ); var_dump( $errs ); var_dump( $xml ); Expected result: ---------------- Either: $success == false && ! empty( $errs ) && $xml === '<?xml version="1.0"?>' or $success == true && empty( $errs ) && $xml === '<?xml version="1.0"?> <root/> ' That is, if libxml_get_errors() is going to return errors then DOMDocument::load() should return false. If DOMDocument::load() is going to succeed, then @xml:space should be ignored and libxml_clear_errors() should be called internally before DOMDocument::load() returns. Either alternative conforms to the XML spec, which says [1]: This specification does not give meaning to any value of xml:space other than "default" and "preserve". It is an error for other values to be specified; the XML processor may report the error or may recover by ignoring the attribute specification or by reporting the (erroneous) value to the application. Applications may ignore or reject erroneous values. The status quo does not conform to the XML spec because it both reports the error and fails to ignore the @xml:space attribute. I VERY MUCH prefer the first alternative, as it is consistent with XMLReader which correctly reports the well-formedness error and refuses to parse test.xml. [1] https://www.w3.org/TR/REC-xml/#sec-white-space Actual result: -------------- bool(true) array(1) { [0]=> object(LibXMLError)#260 (6) { ["level"]=> int(1) ["code"]=> int(102) ["column"]=> int(16) ["message"]=> string(69) "Invalid value "foo" for xml:space : "default" or "preserve" expected " ["file"]=> string(87) "file://test.xml" ["line"]=> int(2) } } string(80) "<?xml version="1.0"?> <root xml:space="foo"/> " -- Edit bug report at https://bugs.php.net/bug.php?id=74988&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=74988&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=74988&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=74988&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=74988&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=74988&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=74988&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=74988&r=needscript Try newer version: https://bugs.php.net/fix.php?id=74988&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=74988&r=support Expected behavior: https://bugs.php.net/fix.php?id=74988&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=74988&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=74988&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=74988&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74988&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=74988&r=dst IIS Stability: https://bugs.php.net/fix.php?id=74988&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=74988&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=74988&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=74988&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=74988&r=mysqlcfg

« previous php.bugs (#210326) next »