#44367 [NEW]: DOMDocument::baseURI parsing is out of whack
From: daniel dot oconnor at gmail dot com
Operating system: Windows
PHP version: 5.2.5
PHP Bug Type: DOM XML related
Bug description: DOMDocument::baseURI parsing is out of whack
Description:
------------
The W3C clarified a few xml:base issues when publishing the GRDDL spec.
You can see the tests at
http://www.w3.org/TR/grddl-tests/#ambiguous-infoset.
Basically:
* DOMDocument::loadXML does not detect xml:base attributes
* simplexml_load_file does not detect xml:base attributes (or they are
lost during the importNode phase)
* simplexml_load_string does not detect xml:base attributes (or they are
lost during the importNode phase)
* DOMDocument does not deal with nested xml:base
* DOMDocument does not deal with redirected xml:base locations
To clarify on the redirect-xml:base stuff...
If I request http://foo.com/example.xml
and that redirects me to http://bar.com/example.xml
and bar.com/example.xml said xml:base = http://foo.com/example.xml
... then http://bar.com/example.xml's baseURI
should be
http://bar.com/example.xml
Reproduce code:
---------------
<?php
$url = 'http://www.w3.org/2001/sw/grddl-wg/td/base/xmlWithBase.xml';
$xml = file_get_contents($url);
//Load a url
$doc = DOMDocument::load($url);
var_dump($doc->baseURI); //Expected
http://www.w3.org/2001/sw/grddl-wg/td/base/xmlWithBase.xml
//Load an xml document with xml:base
$doc = DOMDocument::loadXML($xml);
var_dump($doc->baseURI); //Expected
http://www.w3.org/2001/sw/grddl-wg/td/base/xmlWithBase.xml
//Does it work with importNode?
$sxe = simplexml_load_file($url);
$dom_sxe = dom_import_simplexml($sxe);
$dom = new DOMDocument('1.0');
$dom_sxe = $dom->importNode($dom_sxe, true);
$dom_sxe = $dom->appendChild($dom_sxe);
var_dump($doc->baseURI); //Expected (maybe)
http://www.w3.org/2001/sw/grddl-wg/td/base/xmlWithBase.xml
// Alternative?
$sxe = simplexml_load_string($xml);
$dom_sxe = dom_import_simplexml($sxe);
$dom = new DOMDocument('1.0');
$dom_sxe = $dom->importNode($dom_sxe, true);
$dom_sxe = $dom->appendChild($dom_sxe);
var_dump($doc->baseURI); //Expected (maybe)
http://www.w3.org/2001/sw/grddl-wg/td/base/xmlWithBase.xml
//What about documents with an invalid xml:base (not on the top level
element)?
$doc =
DOMDocument::load('http://www.w3.org/2001/sw/grddl-wg/td/inline-rdf6.xml');
var_dump($doc->baseURI); //Expected http://wwww.example.org/
//What about documents with a *redirected xml:base* ?
//Note: this test case is a little broken because of a W3C server change -
it *should* redirect to
'http://www.w3.org/2001/sw/grddl-wg/td/base/xmlWithBase.xml'
// and thus have a funky new xml:base value
$doc =
DOMDocument::load('http://www.w3.org/2001/sw/grddl-wg/td/xmlWithBase.xml');
var_dump($doc->baseURI); //Expected
http://www.w3.org/2001/sw/grddl-wg/td/base/xmlWithBase.xml
Expected result:
----------------
See reproduce code
Actual result:
--------------
See reproduce code
--
Edit bug report at http://bugs.php.net/?id=44367&edit=1
--
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=44367&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=44367&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=44367&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=44367&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=44367&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=44367&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=44367&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=44367&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=44367&r=support
Expected behavior: http://bugs.php.net/fix.php?id=44367&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=44367&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=44367&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=44367&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=44367&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=44367&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=44367&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=44367&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=44367&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=44367&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=44367&r=mysqlcfg
Thread (9 messages)
- daniel dot oconnor at gmail dot com