Skip to content

Commit

Permalink
Various bugs. Remove auto setting of default url to '/' if a url is s…
Browse files Browse the repository at this point in the history
…upplied

to the constructor. May cause BC issues.


git-svn-id: http://svn.php.net/repository/pear/packages/Net_URL/trunk@119169 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
Richard Heyes committed Mar 6, 2003
1 parent c753e56 commit 28bf42d
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions URL.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | // | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
// | | // | |
// +-----------------------------------------------------------------------+ // +-----------------------------------------------------------------------+
// | Author: Richard Heyes <richard@phpguru.org> | // | Author: Richard Heyes <richard@php.net> |
// +-----------------------------------------------------------------------+ // +-----------------------------------------------------------------------+
// //
// Net_URL Class // Net_URL Class
Expand Down Expand Up @@ -102,7 +102,10 @@ class Net_URL
* Parses the given url and stores the various parts * Parses the given url and stores the various parts
* Defaults are used in certain cases * Defaults are used in certain cases
* *
* @param $url The url * @param string $url Optional URL
* @param bool $useBrackets Whether to use square brackets when
* multiple querystrings with the same name
* exist
*/ */
function Net_URL($url = null, $useBrackets = true) function Net_URL($url = null, $useBrackets = true)
{ {
Expand All @@ -120,23 +123,22 @@ function Net_URL($url = null, $useBrackets = true)
} }
} }


$this->useBrackets = $useBrackets;
$this->url = $url; $this->url = $url;
$this->protocol = 'http' . (@$HTTP_SERVER_VARS['HTTPS'] == 'on' ? 's' : ''); $this->protocol = 'http' . (@$HTTP_SERVER_VARS['HTTPS'] == 'on' ? 's' : '');
$this->user = ''; $this->user = '';
$this->pass = ''; $this->pass = '';
$this->host = !empty($host) ? $host : (isset($HTTP_SERVER_VARS['SERVER_NAME']) ? $HTTP_SERVER_VARS['SERVER_NAME'] : 'localhost'); $this->host = !empty($host) ? $host : (isset($HTTP_SERVER_VARS['SERVER_NAME']) ? $HTTP_SERVER_VARS['SERVER_NAME'] : 'localhost');
$this->port = !empty($port) ? $port : (isset($HTTP_SERVER_VARS['SERVER_PORT']) ? $HTTP_SERVER_VARS['SERVER_PORT'] : 80); $this->port = !empty($port) ? $port : (isset($HTTP_SERVER_VARS['SERVER_PORT']) ? $HTTP_SERVER_VARS['SERVER_PORT'] : 80);
$this->path = $HTTP_SERVER_VARS['PHP_SELF']; $this->path = !empty($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : '/';
$this->querystring = isset($HTTP_SERVER_VARS['QUERY_STRING']) ? $this->_parseRawQuerystring($HTTP_SERVER_VARS['QUERY_STRING']) : null; $this->querystring = isset($HTTP_SERVER_VARS['QUERY_STRING']) ? $this->_parseRawQuerystring($HTTP_SERVER_VARS['QUERY_STRING']) : null;
$this->anchor = ''; $this->anchor = '';
$this->useBrackets = $useBrackets;


// Parse the url and store the various parts // Parse the url and store the various parts
if (!empty($url)) { if (!empty($url)) {
$urlinfo = parse_url($url); $urlinfo = parse_url($url);


// Default path and querystring // Default querystring
$this->path = '/';
$this->querystring = array(); $this->querystring = array();


foreach ($urlinfo as $key => $value) { foreach ($urlinfo as $key => $value) {
Expand All @@ -153,7 +155,7 @@ function Net_URL($url = null, $useBrackets = true)
break; break;


case 'path': case 'path':
if ($value[0] == '/') { if ($value{0} == '/') {
$this->path = $value; $this->path = $value;
} else { } else {
$path = dirname($this->path) == DIRECTORY_SEPARATOR ? '' : dirname($this->path); $path = dirname($this->path) == DIRECTORY_SEPARATOR ? '' : dirname($this->path);
Expand Down Expand Up @@ -197,9 +199,9 @@ function getURL()
/** /**
* Adds a querystring item * Adds a querystring item
* *
* @param $name Name of item * @param string $name Name of item
* @param $value Value of item * @param string $value Value of item
* @param $preencoded Whether value is urlencoded or not, default = not * @param bool $preencoded Whether value is urlencoded or not, default = not
* @access public * @access public
*/ */
function addQueryString($name, $value, $preencoded = false) function addQueryString($name, $value, $preencoded = false)
Expand All @@ -215,8 +217,8 @@ function addQueryString($name, $value, $preencoded = false)
/** /**
* Removes a querystring item * Removes a querystring item
* *
* @param $name Name of item * @param string $name Name of item
* @access public<> * @access public
*/ */
function removeQueryString($name) function removeQueryString($name)
{ {
Expand All @@ -228,7 +230,7 @@ function removeQueryString($name)
/** /**
* Sets the querystring to literally what you supply * Sets the querystring to literally what you supply
* *
* @param $querystring The querystring data. Should be of the format foo=bar&x=y etc * @param string $querystring The querystring data. Should be of the format foo=bar&x=y etc
* @access public * @access public
*/ */
function addRawQueryString($querystring) function addRawQueryString($querystring)
Expand Down

0 comments on commit 28bf42d

Please sign in to comment.