Req #65364 [NEW]: baseURI should always be a real URI
| From: | mike at skew dot org | Date: | Wed, 31 Jul 2013 05:28:46 +0000 |
| Subject: | Req #65364 [NEW]: baseURI should always be a real URI | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-180610@lists.php.net to get a copy of this message | ||
From: mike at skew dot org
Operating system: FreeBSD 8.4-RELEASE
PHP version: 5.4.17
Package: DOM XML related
Bug Type: Feature/Change Request
Bug description:baseURI should always be a real URI
Description:
------------
When loading an XML document from memory (string, file, whatever), such as
via
DOMDocument::loadXml(), PHP tells libxml to use the current working
directory,
or I think sometimes the script's folder path, as the base URI. libxml (and
PHP's thin API) expose this value as the baseURI property in the DOM,
overriding
it only as needed when xml:base is in scope.
As pointed out in the comments on Bug #44367, neither PHP nor libxml claim
to
support DOM Core Level 3, so maybe this PHP/libxml "baseURI" property
shouldn't
be expected to behave as it would in a L3-compliant DOM. Nevertheless, I
think
it's reasonable to expect that something called "baseURI" would in fact be
formatted as a URI, thus making it useful as an actual base URI for
resolving
URI references like href attribute values in XHTML documents and Atom
feeds.
So, my request is that the path be prefixed with "file://", at the very
least.
This will have the added benefit of making things forward-compatible with
DOM
Core L3, if such support is intended for the future.
Also, my experience with XML apps suggests that a more typical default
would be
a file URI corresponding to the script itself, rather than the cwd or
script
folder. This would have no effect on resolution of relative references
(except
an empty string), so it seems harmless in that regard. However, I would
understand if there's a desire to avoid disclosing the script's file name
in the
DOM.
Test script:
---------------
<?php
$xml_string = "<greeting>hello world</greeting>";
$doc = new DOMDocument();
$doc->loadXml($xml_string);
$document_base = $doc->baseURI;
$document_element_base = $doc->documentElement->baseURI;
echo " DOMDocument->baseURI = " . $document_base;
// A URI, as opposed to a URI reference, is always absolute.
// That is, it has a scheme/protocol (something before ":").
echo (strpos($document_base, ":") == false ? " (not a real URI!)" : "
(probably OK!)") . "\n";
echo " DocumentElement->baseURI = " . $document_element_base;
echo (strpos($document_element_base, ":") == false ? " (not a real URI!)" :
" (probably OK!)") . "\n";
?>
Expected result:
----------------
DOMDocument->baseURI = file:///usr/home/x/ (probably OK!)
DocumentElement->baseURI = file:///usr/home/x/ (probably OK!)
Actual result:
--------------
DOMDocument->baseURI = /usr/home/x/ (not a real URI!)
DocumentElement->baseURI = /usr/home/x/ (not a real URI!)
--
Edit bug report at https://bugs.php.net/bug.php?id=65364&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=65364&r=trysnapshot54
Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=65364&r=trysnapshot53
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=65364&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=65364&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=65364&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=65364&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=65364&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=65364&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=65364&r=support
Expected behavior: https://bugs.php.net/fix.php?id=65364&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=65364&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=65364&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=65364&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65364&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=65364&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=65364&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=65364&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=65364&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=65364&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=65364&r=mysqlcfg