From 2e00c2490fb544596fba06483ad1c1d626c1fd4f Mon Sep 17 00:00:00 2001 From: Stephen Date: Sun, 28 Aug 2011 10:25:40 +0200 Subject: Added tests for CI_URI class. Made modifications to core class which helped with isolation for testing. --- system/core/URI.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index a3ae20cc3..51c2191af 100755 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -87,7 +87,7 @@ class CI_URI { if (strtoupper($this->config->item('uri_protocol')) == 'AUTO') { // Is the request coming from the command line? - if (php_sapi_name() == 'cli' or defined('STDIN')) + if ($this->_is_cli_request()) { $this->_set_uri_string($this->_parse_cli_args()); return; @@ -222,6 +222,21 @@ class CI_URI { return str_replace(array('//', '../'), '/', trim($uri, '/')); } + // -------------------------------------------------------------------- + + /** + * Is cli Request? + * + * Duplicate of function from the Input class to test to see if a request was made from the command line + * + * @return boolean + */ + protected function _is_cli_request() + { + return (php_sapi_name() == 'cli') OR defined('STDIN'); + } + + // -------------------------------------------------------------------- /** -- cgit v1.2.3-24-g4f1b From f4a4bd8fac188ebc9cda822ffc811c218fd92b45 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 20 Oct 2011 12:18:42 -0500 Subject: adding new license file (OSL 3.0) and updating readme to ReST added notice of license to all source files. OSL to all except the few files we ship inside of the application folder, those are AFL. Updated license in user guide. incrementing next dev version to 3.0 due to licensing change --- system/core/URI.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index 8946bc76b..578d17429 100755 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -4,10 +4,22 @@ * * An open source application development framework for PHP 5.1.6 or newer * + * NOTICE OF LICENSE + * + * Licensed under the Open Software License version 3.0 + * + * This source file is subject to the Open Software License (OSL 3.0) that is + * bundled with this package in the files license.txt / license.rst. It is + * also available through the world wide web at this URL: + * http://opensource.org/licenses/OSL-3.0 + * If you did not receive a copy of the license and are unable to obtain it + * through the world wide web, please send an email to + * licensing@ellislab.com so we can send you a copy immediately. + * * @package CodeIgniter - * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. - * @license http://codeigniter.com/user_guide/license.html + * @author EllisLab Dev Team + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 * @filesource @@ -23,7 +35,7 @@ * @package CodeIgniter * @subpackage Libraries * @category URI - * @author ExpressionEngine Dev Team + * @author EllisLab Dev Team * @link http://codeigniter.com/user_guide/libraries/uri.html */ class CI_URI { -- cgit v1.2.3-24-g4f1b From 0defe5d33ee2633f377a109519ca818becc60f64 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Sun, 1 Jan 2012 18:46:41 -0600 Subject: Updating copyright date to 2012 --- system/core/URI.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index 578d17429..3c26d307b 100755 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 -- cgit v1.2.3-24-g4f1b From c123e118de32e2b31b9bf21fdb43458bc9f4cbda Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 8 Jan 2012 00:17:34 +0200 Subject: Improve core URI & UTF8 libraries --- system/core/URI.php | 197 ++++++++++++++++++++++------------------------------ 1 file changed, 84 insertions(+), 113 deletions(-) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index 3c26d307b..93105b1fd 100755 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -1,13 +1,13 @@ -config =& load_class('Config', 'core'); - log_message('debug', "URI Class Initialized"); + log_message('debug', 'URI Class Initialized'); } - // -------------------------------------------------------------------- /** * Get the URI String * - * @access private - * @return string + * Called by CI_Router + * + * @return void */ - function _fetch_uri_string() + public function _fetch_uri_string() { - if (strtoupper($this->config->item('uri_protocol')) == 'AUTO') + if (strtoupper($this->config->item('uri_protocol')) === 'AUTO') { // Is the request coming from the command line? - if (php_sapi_name() == 'cli' or defined('STDIN')) + if (php_sapi_name() === 'cli' OR defined('STDIN')) { $this->_set_uri_string($this->_parse_cli_args()); return; @@ -115,14 +109,14 @@ class CI_URI { // Is there a PATH_INFO variable? // Note: some servers seem to have trouble with getenv() so we'll test it two ways $path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); - if (trim($path, '/') != '' && $path != "/".SELF) + if (trim($path, '/') != '' && $path !== '/'.SELF) { $this->_set_uri_string($path); return; } // No PATH_INFO?... What about QUERY_STRING? - $path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); + $path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); if (trim($path, '/') != '') { $this->_set_uri_string($path); @@ -130,7 +124,7 @@ class CI_URI { } // As a last ditch effort lets try using the $_GET array - if (is_array($_GET) && count($_GET) == 1 && trim(key($_GET), '/') != '') + if (is_array($_GET) && count($_GET) === 1 && trim(key($_GET), '/') != '') { $this->_set_uri_string(key($_GET)); return; @@ -143,12 +137,12 @@ class CI_URI { $uri = strtoupper($this->config->item('uri_protocol')); - if ($uri == 'REQUEST_URI') + if ($uri === 'REQUEST_URI') { $this->_set_uri_string($this->_detect_uri()); return; } - elseif ($uri == 'CLI') + elseif ($uri === 'CLI') { $this->_set_uri_string($this->_parse_cli_args()); return; @@ -163,17 +157,16 @@ class CI_URI { /** * Set the URI String * - * @access public * @param string - * @return string + * @return void */ - function _set_uri_string($str) + public function _set_uri_string($str) { // Filter out control characters $str = remove_invisible_characters($str, FALSE); // If the URI contains only a slash we'll kill it - $this->uri_string = ($str == '/') ? '' : $str; + $this->uri_string = ($str === '/') ? '' : $str; } // -------------------------------------------------------------------- @@ -184,7 +177,6 @@ class CI_URI { * This function will detect the URI automatically and fix the query string * if necessary. * - * @access private * @return string */ protected function _detect_uri() @@ -194,12 +186,11 @@ class CI_URI { return ''; } - $uri = $_SERVER['REQUEST_URI']; - if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0) + if (strpos($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME']) === 0) { $uri = substr($uri, strlen($_SERVER['SCRIPT_NAME'])); } - elseif (strpos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0) + elseif (strpos($_SERVER['REQUEST_URI'], dirname($_SERVER['SCRIPT_NAME'])) === 0) { $uri = substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME']))); } @@ -223,7 +214,7 @@ class CI_URI { $_GET = array(); } - if ($uri == '/' || empty($uri)) + if ($uri == '/' OR empty($uri)) { return '/'; } @@ -241,13 +232,11 @@ class CI_URI { * * Take each command line argument and assume it is a URI segment. * - * @access private * @return string */ protected function _parse_cli_args() { $args = array_slice($_SERVER['argv'], 1); - return $args ? '/' . implode('/', $args) : ''; } @@ -256,27 +245,28 @@ class CI_URI { /** * Filter segments for malicious characters * - * @access private + * Called by CI_Router + * * @param string * @return string */ - function _filter_uri($str) + public function _filter_uri($str) { if ($str != '' && $this->config->item('permitted_uri_chars') != '' && $this->config->item('enable_query_strings') == FALSE) { // preg_quote() in PHP 5.3 escapes -, so the str_replace() and addition of - to preg_quote() is to maintain backwards // compatibility as many are unaware of how characters in the permitted_uri_chars will be parsed as a regex pattern - if ( ! preg_match("|^[".str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-'))."]+$|i", $str)) + if ( ! preg_match('|^['.str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-')).']+$|i', $str)) { show_error('The URI you submitted has disallowed characters.', 400); } } - // Convert programatic characters to entities - $bad = array('$', '(', ')', '%28', '%29'); - $good = array('$', '(', ')', '(', ')'); - - return str_replace($bad, $good, $str); + // Convert programatic characters to entities and return + return str_replace( + array('$', '(', ')', '%28', '%29'), // Bad + array('$', '(', ')', '(', ')'), // Good + $str); } // -------------------------------------------------------------------- @@ -284,14 +274,15 @@ class CI_URI { /** * Remove the suffix from the URL if needed * - * @access private + * Called by CI_Router + * * @return void */ - function _remove_url_suffix() + public function _remove_url_suffix() { - if ($this->config->item('url_suffix') != "") + if ($this->config->item('url_suffix') != '') { - $this->uri_string = preg_replace("|".preg_quote($this->config->item('url_suffix'))."$|", "", $this->uri_string); + $this->uri_string = preg_replace('|'.preg_quote($this->config->item('url_suffix')).'$|', '', $this->uri_string); } } @@ -301,12 +292,13 @@ class CI_URI { * Explode the URI Segments. The individual segments will * be stored in the $this->segments array. * - * @access private + * Called by CI_Router + * * @return void */ - function _explode_segments() + public function _explode_segments() { - foreach (explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $this->uri_string)) as $val) + foreach (explode('/', preg_replace('|/*(.+?)/*$|', '\\1', $this->uri_string)) as $val) { // Filter segments for security $val = trim($this->_filter_uri($val)); @@ -323,14 +315,15 @@ class CI_URI { * Re-index Segments * * This function re-indexes the $this->segment array so that it - * starts at 1 rather than 0. Doing so makes it simpler to + * starts at 1 rather than 0. Doing so makes it simpler to * use functions like $this->uri->segment(n) since there is * a 1:1 relationship between the segment array and the actual segments. * - * @access private + * Called by CI_Router + * * @return void */ - function _reindex_segments() + public function _reindex_segments() { array_unshift($this->segments, NULL); array_unshift($this->rsegments, NULL); @@ -345,12 +338,11 @@ class CI_URI { * * This function returns the URI segment based on the number provided. * - * @access public * @param integer * @param bool * @return string */ - function segment($n, $no_result = FALSE) + public function segment($n, $no_result = FALSE) { return ( ! isset($this->segments[$n])) ? $no_result : $this->segments[$n]; } @@ -364,12 +356,11 @@ class CI_URI { * based on the number provided. If there is no routing this function returns the * same result as $this->segment() * - * @access public * @param integer * @param bool * @return string */ - function rsegment($n, $no_result = FALSE) + public function rsegment($n, $no_result = FALSE) { return ( ! isset($this->rsegments[$n])) ? $no_result : $this->rsegments[$n]; } @@ -392,25 +383,22 @@ class CI_URI { * gender => male * ) * - * @access public * @param integer the starting segment number * @param array an array of default values * @return array */ - function uri_to_assoc($n = 3, $default = array()) + public function uri_to_assoc($n = 3, $default = array()) { return $this->_uri_to_assoc($n, $default, 'segment'); } /** * Identical to above only it uses the re-routed segment array * - * @access public * @param integer the starting segment number * @param array an array of default values * @return array - * */ - function ruri_to_assoc($n = 3, $default = array()) + public function ruri_to_assoc($n = 3, $default = array()) { return $this->_uri_to_assoc($n, $default, 'rsegment'); } @@ -420,25 +408,13 @@ class CI_URI { /** * Generate a key value pair from the URI string or Re-routed URI string * - * @access private * @param integer the starting segment number * @param array an array of default values * @param string which array we should use * @return array */ - function _uri_to_assoc($n = 3, $default = array(), $which = 'segment') + protected function _uri_to_assoc($n = 3, $default = array(), $which = 'segment') { - if ($which == 'segment') - { - $total_segments = 'total_segments'; - $segment_array = 'segment_array'; - } - else - { - $total_segments = 'total_rsegments'; - $segment_array = 'rsegment_array'; - } - if ( ! is_numeric($n)) { return $default; @@ -449,23 +425,30 @@ class CI_URI { return $this->keyval[$n]; } + if ($which === 'segment') + { + $total_segments = 'total_segments'; + $segment_array = 'segment_array'; + } + else + { + $total_segments = 'total_rsegments'; + $segment_array = 'rsegment_array'; + } + if ($this->$total_segments() < $n) { - if (count($default) == 0) + if (count($default) === 0) { return array(); } - $retval = array(); - foreach ($default as $val) - { - $retval[$val] = FALSE; - } - return $retval; + return function_exists('array_fill_keys') + ? array_fill_keys($default, FALSE) + : array_combine($default, array_fill(0, count($default), FALSE)); } $segments = array_slice($this->$segment_array(), ($n - 1)); - $i = 0; $lastval = ''; $retval = array(); @@ -506,16 +489,15 @@ class CI_URI { * Generate a URI string from an associative array * * - * @access public * @param array an associative array of key/values * @return array */ - function assoc_to_uri($array) + public function assoc_to_uri($array) { $temp = array(); foreach ((array)$array as $key => $val) { - $temp[] = $key; + $temp[] = $key; $temp[] = $val; } @@ -527,12 +509,11 @@ class CI_URI { /** * Fetch a URI Segment and add a trailing slash * - * @access public * @param integer * @param string * @return string */ - function slash_segment($n, $where = 'trailing') + public function slash_segment($n, $where = 'trailing') { return $this->_slash_segment($n, $where, 'segment'); } @@ -542,12 +523,11 @@ class CI_URI { /** * Fetch a URI Segment and add a trailing slash * - * @access public * @param integer * @param string * @return string */ - function slash_rsegment($n, $where = 'trailing') + public function slash_rsegment($n, $where = 'trailing') { return $this->_slash_segment($n, $where, 'rsegment'); } @@ -557,22 +537,20 @@ class CI_URI { /** * Fetch a URI Segment and add a trailing slash - helper function * - * @access private * @param integer * @param string * @param string * @return string */ - function _slash_segment($n, $where = 'trailing', $which = 'segment') + protected function _slash_segment($n, $where = 'trailing', $which = 'segment') { - $leading = '/'; - $trailing = '/'; + $leading = $trailing = '/'; - if ($where == 'trailing') + if ($where === 'trailing') { $leading = ''; } - elseif ($where == 'leading') + elseif ($where === 'leading') { $trailing = ''; } @@ -585,10 +563,9 @@ class CI_URI { /** * Segment Array * - * @access public * @return array */ - function segment_array() + public function segment_array() { return $this->segments; } @@ -598,10 +575,9 @@ class CI_URI { /** * Routed Segment Array * - * @access public * @return array */ - function rsegment_array() + public function rsegment_array() { return $this->rsegments; } @@ -611,10 +587,9 @@ class CI_URI { /** * Total number of segments * - * @access public * @return integer */ - function total_segments() + public function total_segments() { return count($this->segments); } @@ -624,10 +599,9 @@ class CI_URI { /** * Total number of routed segments * - * @access public * @return integer */ - function total_rsegments() + public function total_rsegments() { return count($this->rsegments); } @@ -637,10 +611,9 @@ class CI_URI { /** * Fetch the entire URI string * - * @access public * @return string */ - function uri_string() + public function uri_string() { return $this->uri_string; } @@ -651,16 +624,14 @@ class CI_URI { /** * Fetch the entire Re-routed URI string * - * @access public * @return string */ - function ruri_string() + public function ruri_string() { return '/'.implode('/', $this->rsegment_array()); } } -// END URI Class /* End of file URI.php */ -/* Location: ./system/core/URI.php */ \ No newline at end of file +/* Location: ./system/core/URI.php */ -- cgit v1.2.3-24-g4f1b From a798fdb9a08a6f549bcc2a4ea6c6bad45cfef0a2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 8 Jan 2012 00:20:49 +0200 Subject: Remove a space :) --- system/core/URI.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index 93105b1fd..eaf7b752b 100755 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -497,7 +497,7 @@ class CI_URI { $temp = array(); foreach ((array)$array as $key => $val) { - $temp[] = $key; + $temp[] = $key; $temp[] = $val; } -- cgit v1.2.3-24-g4f1b From 0609d588a4340fc9a9cfbc0ff76c39bba9ab09fb Mon Sep 17 00:00:00 2001 From: Michiel Vugteveen Date: Sun, 8 Jan 2012 13:26:17 +0100 Subject: Fixes for issue 896 --- system/core/URI.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index eaf7b752b..b28ee198b 100755 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -186,11 +186,12 @@ class CI_URI { return ''; } - if (strpos($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME']) === 0) + $uri = $_SERVER['REQUEST_URI']; + if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0) { $uri = substr($uri, strlen($_SERVER['SCRIPT_NAME'])); } - elseif (strpos($_SERVER['REQUEST_URI'], dirname($_SERVER['SCRIPT_NAME'])) === 0) + elseif (strpos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0) { $uri = substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME']))); } -- cgit v1.2.3-24-g4f1b From 07c1ac830b4e98aa40f48baef3dd05fb68c0a836 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Fri, 9 Mar 2012 17:03:37 +0000 Subject: Bumped CodeIgniter's PHP requirement to 5.2.4. Yes I know PHP 5.4 just came out, and yes I know PHP 5.3 has lovely features, but there are plenty of corporate systems running on CodeIgniter and PHP 5.3 still is not widely supported enough. CodeIgniter is great for distributed applications, and this is the highest we can reasonably go without breaking support. PHP 5.3 will most likely happen in another year or so. Fingers crossed on that one anyway... --- system/core/URI.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index b28ee198b..db5b8e44b 100755 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 5.1.6 or newer + * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE * -- cgit v1.2.3-24-g4f1b From 1ae651655888383a4d7f97fbf6e97a7ac00a9630 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 10 Mar 2012 16:11:34 +0200 Subject: Remove PHP 5.1.6-specific code --- system/core/URI.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index db5b8e44b..4a2e87c2a 100755 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -444,9 +444,7 @@ class CI_URI { return array(); } - return function_exists('array_fill_keys') - ? array_fill_keys($default, FALSE) - : array_combine($default, array_fill(0, count($default), FALSE)); + return array_fill_keys($default, FALSE); } $segments = array_slice($this->$segment_array(), ($n - 1)); -- cgit v1.2.3-24-g4f1b From 40403d21274d5e0792c7ab816ad984d6387d5c20 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Thu, 19 Apr 2012 16:38:50 -0400 Subject: Additional formatting fixes --- system/core/URI.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index 48bb7ae3c..140295338 100755 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -24,8 +24,6 @@ * @since Version 1.0 */ -// ------------------------------------------------------------------------ - /** * URI Class * @@ -44,26 +42,29 @@ class CI_URI { * * @var array */ - public $keyval = array(); + public $keyval = array(); + /** * Current uri string * * @var string */ public $uri_string; + /** * List of uri segments * * @var array */ - public $segments = array(); + public $segments = array(); + /** * Re-indexed list of uri segments * Starts at 1 instead of 0 * * @var array */ - public $rsegments = array(); + public $rsegments = array(); /** * Constructor @@ -326,6 +327,7 @@ class CI_URI { } // -------------------------------------------------------------------- + /** * Re-index Segments * @@ -406,6 +408,9 @@ class CI_URI { { return $this->_uri_to_assoc($n, $default, 'segment'); } + + // -------------------------------------------------------------------- + /** * Identical to above only it uses the re-routed segment array * @@ -501,7 +506,6 @@ class CI_URI { /** * Generate a URI string from an associative array * - * * @param array an associative array of key/values * @return array */ @@ -647,4 +651,4 @@ class CI_URI { } /* End of file URI.php */ -/* Location: ./system/core/URI.php */ +/* Location: ./system/core/URI.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 48a7fbbeb53e82e9298036d40c42ec2564699ed0 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 23 Apr 2012 11:58:16 -0400 Subject: Use tabs to separate class properties --- system/core/URI.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index 140295338..ff2c458b8 100755 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -42,7 +42,7 @@ class CI_URI { * * @var array */ - public $keyval = array(); + public $keyval = array(); /** * Current uri string @@ -56,7 +56,7 @@ class CI_URI { * * @var array */ - public $segments = array(); + public $segments = array(); /** * Re-indexed list of uri segments @@ -64,7 +64,7 @@ class CI_URI { * * @var array */ - public $rsegments = array(); + public $rsegments = array(); /** * Constructor -- cgit v1.2.3-24-g4f1b From cdfbd5281e4dec7278a07943832c2590c1141eb3 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Thu, 26 Apr 2012 22:13:31 +0100 Subject: Fixed issue #122 - ruri_string() in subdirs. --- system/core/URI.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index 48bb7ae3c..17300df07 100755 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -641,10 +641,10 @@ class CI_URI { */ public function ruri_string() { - return '/'.implode('/', $this->rsegment_array()); + return implode('/', $this->rsegment_array()); } } /* End of file URI.php */ -/* Location: ./system/core/URI.php */ +/* Location: ./system/core/URI.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 81aa94bbb533737c19a705d5b8864bd47fbab85c Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Wed, 2 May 2012 11:40:46 +0100 Subject: Reverted rui_string change. This had knock-on effects as can be seen in #1306. Issue #122 has been reopend until it is fixed properly. --- system/core/URI.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index 705575a0c..cf82c5838 100755 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -645,10 +645,10 @@ class CI_URI { */ public function ruri_string() { - return implode('/', $this->rsegment_array()); + return '/'.implode('/', $this->rsegment_array()); } } /* End of file URI.php */ -/* Location: ./system/core/URI.php */ \ No newline at end of file +/* Location: ./system/core/URI.php */ -- cgit v1.2.3-24-g4f1b From 92ebfb65ac044f5c2e6d88fba137253854cf1b94 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 17 May 2012 12:49:24 +0300 Subject: Cleanup the core classes --- system/core/URI.php | 67 ++++++++++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 34 deletions(-) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index cf82c5838..e66cb6dc5 100755 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -22,6 +22,7 @@ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 + * @filesource */ /** @@ -43,21 +44,21 @@ class CI_URI { * @var array */ public $keyval = array(); - + /** * Current uri string * * @var string */ public $uri_string; - + /** * List of uri segments * * @var array */ public $segments = array(); - + /** * Re-indexed list of uri segments * Starts at 1 instead of 0 @@ -72,6 +73,8 @@ class CI_URI { * Simply globalizes the $RTR object. The front * loads the Router class early on so it's not available * normally as other classes are. + * + * @return void */ public function __construct() { @@ -148,7 +151,7 @@ class CI_URI { return; } - $path = (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri); + $path = isset($_SERVER[$uri]) ? $_SERVER[$uri] : @getenv($uri); $this->_set_uri_string($path); } @@ -181,7 +184,7 @@ class CI_URI { */ protected function _detect_uri() { - if ( ! isset($_SERVER['REQUEST_URI']) OR ! isset($_SERVER['SCRIPT_NAME'])) + if ( ! isset($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME'])) { return ''; } @@ -227,20 +230,19 @@ class CI_URI { } // -------------------------------------------------------------------- - + /** * Is cli Request? * * Duplicate of function from the Input class to test to see if a request was made from the command line * - * @return boolean + * @return bool */ protected function _is_cli_request() { - return (php_sapi_name() == 'cli') OR defined('STDIN'); + return (php_sapi_name() === 'cli') OR defined('STDIN'); } - // -------------------------------------------------------------------- /** @@ -253,7 +255,7 @@ class CI_URI { protected function _parse_cli_args() { $args = array_slice($_SERVER['argv'], 1); - return $args ? '/' . implode('/', $args) : ''; + return $args ? '/'.implode('/', $args) : ''; } // -------------------------------------------------------------------- @@ -327,7 +329,7 @@ class CI_URI { } // -------------------------------------------------------------------- - + /** * Re-index Segments * @@ -355,13 +357,13 @@ class CI_URI { * * This function returns the URI segment based on the number provided. * - * @param integer + * @param int * @param bool * @return string */ public function segment($n, $no_result = FALSE) { - return ( ! isset($this->segments[$n])) ? $no_result : $this->segments[$n]; + return isset($this->segments[$n]) ? $this->segments[$n] : $no_result; } // -------------------------------------------------------------------- @@ -370,16 +372,16 @@ class CI_URI { * Fetch a URI "routed" Segment * * This function returns the re-routed URI segment (assuming routing rules are used) - * based on the number provided. If there is no routing this function returns the + * based on the number provided. If there is no routing this function returns the * same result as $this->segment() * - * @param integer + * @param int * @param bool * @return string */ public function rsegment($n, $no_result = FALSE) { - return ( ! isset($this->rsegments[$n])) ? $no_result : $this->rsegments[$n]; + return isset($this->rsegments[$n]) ? $this->rsegments[$n] : $no_result; } // -------------------------------------------------------------------- @@ -400,7 +402,7 @@ class CI_URI { * gender => male * ) * - * @param integer the starting segment number + * @param int the starting segment number * @param array an array of default values * @return array */ @@ -408,13 +410,13 @@ class CI_URI { { return $this->_uri_to_assoc($n, $default, 'segment'); } - + // -------------------------------------------------------------------- - + /** * Identical to above only it uses the re-routed segment array * - * @param integer the starting segment number + * @param int the starting segment number * @param array an array of default values * @return array */ @@ -428,7 +430,7 @@ class CI_URI { /** * Generate a key value pair from the URI string or Re-routed URI string * - * @param integer the starting segment number + * @param int the starting segment number * @param array an array of default values * @param string which array we should use * @return array @@ -458,12 +460,9 @@ class CI_URI { if ($this->$total_segments() < $n) { - if (count($default) === 0) - { - return array(); - } - - return array_fill_keys($default, FALSE); + return (count($default) === 0) + ? array() + : array_fill_keys($default, FALSE); } $segments = array_slice($this->$segment_array(), ($n - 1)); @@ -512,7 +511,7 @@ class CI_URI { public function assoc_to_uri($array) { $temp = array(); - foreach ((array)$array as $key => $val) + foreach ( (array) $array as $key => $val) { $temp[] = $key; $temp[] = $val; @@ -526,7 +525,7 @@ class CI_URI { /** * Fetch a URI Segment and add a trailing slash * - * @param integer + * @param int * @param string * @return string */ @@ -540,7 +539,7 @@ class CI_URI { /** * Fetch a URI Segment and add a trailing slash * - * @param integer + * @param int * @param string * @return string */ @@ -554,7 +553,7 @@ class CI_URI { /** * Fetch a URI Segment and add a trailing slash - helper function * - * @param integer + * @param int * @param string * @param string * @return string @@ -604,7 +603,7 @@ class CI_URI { /** * Total number of segments * - * @return integer + * @return int */ public function total_segments() { @@ -616,7 +615,7 @@ class CI_URI { /** * Total number of routed segments * - * @return integer + * @return int */ public function total_rsegments() { @@ -651,4 +650,4 @@ class CI_URI { } /* End of file URI.php */ -/* Location: ./system/core/URI.php */ +/* Location: ./system/core/URI.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 55a6ddb0c7bab1149bb1ddfa3a1aff46612c91d4 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Wed, 23 May 2012 18:37:24 +0100 Subject: Input, Session and Cookie get's will return NULL. Read more about this change here: http://codeigniter.com/forums/viewthread/215833 --- system/core/URI.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index e66cb6dc5..a9432e05d 100755 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -358,10 +358,10 @@ class CI_URI { * This function returns the URI segment based on the number provided. * * @param int - * @param bool + * @param mixed * @return string */ - public function segment($n, $no_result = FALSE) + public function segment($n, $no_result = NULL) { return isset($this->segments[$n]) ? $this->segments[$n] : $no_result; } @@ -376,10 +376,10 @@ class CI_URI { * same result as $this->segment() * * @param int - * @param bool + * @param mixed * @return string */ - public function rsegment($n, $no_result = FALSE) + public function rsegment($n, $no_result = NULL) { return isset($this->rsegments[$n]) ? $this->rsegments[$n] : $no_result; } @@ -462,7 +462,7 @@ class CI_URI { { return (count($default) === 0) ? array() - : array_fill_keys($default, FALSE); + : array_fill_keys($default, NULL); } $segments = array_slice($this->$segment_array(), ($n - 1)); @@ -477,7 +477,7 @@ class CI_URI { } else { - $retval[$seg] = FALSE; + $retval[$seg] = NULL; $lastval = $seg; } @@ -490,7 +490,7 @@ class CI_URI { { if ( ! array_key_exists($val, $retval)) { - $retval[$val] = FALSE; + $retval[$val] = NULL; } } } @@ -511,7 +511,7 @@ class CI_URI { public function assoc_to_uri($array) { $temp = array(); - foreach ( (array) $array as $key => $val) + foreach ((array) $array as $key => $val) { $temp[] = $key; $temp[] = $val; @@ -644,7 +644,7 @@ class CI_URI { */ public function ruri_string() { - return '/'.implode('/', $this->rsegment_array()); + return implode('/', $this->rsegment_array()); } } -- cgit v1.2.3-24-g4f1b From ed944a3c70a0bad158cd5a6ca5ce1f2e717aff5d Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sat, 2 Jun 2012 11:07:47 +0100 Subject: Replaced `==` with `===` and `!=` with `!==` in /system/core --- system/core/URI.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index a9432e05d..9c5025128 100755 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -112,7 +112,7 @@ class CI_URI { // Is there a PATH_INFO variable? // Note: some servers seem to have trouble with getenv() so we'll test it two ways $path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); - if (trim($path, '/') != '' && $path !== '/'.SELF) + if (trim($path, '/') !== '' && $path !== '/'.SELF) { $this->_set_uri_string($path); return; @@ -120,14 +120,14 @@ class CI_URI { // No PATH_INFO?... What about QUERY_STRING? $path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); - if (trim($path, '/') != '') + if (trim($path, '/') !== '') { $this->_set_uri_string($path); return; } // As a last ditch effort lets try using the $_GET array - if (is_array($_GET) && count($_GET) === 1 && trim(key($_GET), '/') != '') + if (is_array($_GET) && count($_GET) === 1 && trim(key($_GET), '/') !== '') { $this->_set_uri_string(key($_GET)); return; @@ -218,7 +218,7 @@ class CI_URI { $_GET = array(); } - if ($uri == '/' OR empty($uri)) + if ($uri === '/' OR empty($uri)) { return '/'; } @@ -270,7 +270,7 @@ class CI_URI { */ public function _filter_uri($str) { - if ($str != '' && $this->config->item('permitted_uri_chars') != '' && $this->config->item('enable_query_strings') == FALSE) + if ($str !== '' && $this->config->item('permitted_uri_chars') !== '' && $this->config->item('enable_query_strings') === FALSE) { // preg_quote() in PHP 5.3 escapes -, so the str_replace() and addition of - to preg_quote() is to maintain backwards // compatibility as many are unaware of how characters in the permitted_uri_chars will be parsed as a regex pattern @@ -298,7 +298,7 @@ class CI_URI { */ public function _remove_url_suffix() { - if ($this->config->item('url_suffix') != '') + if ($this->config->item('url_suffix') !== '') { $this->uri_string = preg_replace('|'.preg_quote($this->config->item('url_suffix')).'$|', '', $this->uri_string); } @@ -321,7 +321,7 @@ class CI_URI { // Filter segments for security $val = trim($this->_filter_uri($val)); - if ($val != '') + if ($val !== '') { $this->segments[] = $val; } -- cgit v1.2.3-24-g4f1b From 04d43fea485a65086ae814625c2d687ce6fc13c6 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sat, 2 Jun 2012 17:59:11 +0100 Subject: Fixed bug introduced in ed944a3c70a0bad158cd5a6ca5ce1f2e717aff5d --- system/core/URI.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index 9c5025128..0afb374c2 100755 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -270,7 +270,7 @@ class CI_URI { */ public function _filter_uri($str) { - if ($str !== '' && $this->config->item('permitted_uri_chars') !== '' && $this->config->item('enable_query_strings') === FALSE) + if ($str !== '' && $this->config->item('permitted_uri_chars') != '' && $this->config->item('enable_query_strings') === FALSE) { // preg_quote() in PHP 5.3 escapes -, so the str_replace() and addition of - to preg_quote() is to maintain backwards // compatibility as many are unaware of how characters in the permitted_uri_chars will be parsed as a regex pattern -- cgit v1.2.3-24-g4f1b From 9ba661b02c492e89028e5c67b7edbfc0efefc9f1 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 4 Jun 2012 14:44:34 +0300 Subject: Revert/optimize some changes from ed944a3c70a0bad158cd5a6ca5ce1f2e717aff5d --- system/core/URI.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index 0afb374c2..a575bc36e 100755 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -111,7 +111,7 @@ class CI_URI { // Is there a PATH_INFO variable? // Note: some servers seem to have trouble with getenv() so we'll test it two ways - $path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); + $path = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); if (trim($path, '/') !== '' && $path !== '/'.SELF) { $this->_set_uri_string($path); -- cgit v1.2.3-24-g4f1b From 0d2c06ea1d96ea3f35dd1e7856977a24cec43233 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 12 Jun 2012 02:33:45 +0300 Subject: Change file permissions for system/core/*.php and system/database/DB.php so that they don't differ from the rest --- system/core/URI.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 system/core/URI.php (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php old mode 100755 new mode 100644 -- cgit v1.2.3-24-g4f1b From d461934184d95b0cfb2feec93f27b621ef72a5c2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 14 Jun 2012 02:27:25 +0300 Subject: Fix issue #10 + URI class speed improvements --- system/core/URI.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index a575bc36e..2e661ed4c 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -119,7 +119,7 @@ class CI_URI { } // No PATH_INFO?... What about QUERY_STRING? - $path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); + $path = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); if (trim($path, '/') !== '') { $this->_set_uri_string($path); @@ -163,7 +163,7 @@ class CI_URI { * @param string * @return void */ - public function _set_uri_string($str) + protected function _set_uri_string($str) { // Filter out control characters $str = remove_invisible_characters($str, FALSE); @@ -177,8 +177,8 @@ class CI_URI { /** * Detects the URI * - * This function will detect the URI automatically and fix the query string - * if necessary. + * This function will detect the URI automatically + * and fix the query string if necessary. * * @return string */ @@ -189,7 +189,6 @@ class CI_URI { return ''; } - $uri = $_SERVER['REQUEST_URI']; if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0) { $uri = substr($uri, strlen($_SERVER['SCRIPT_NAME'])); @@ -198,14 +197,19 @@ class CI_URI { { $uri = substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME']))); } + else + { + $uri = $_SERVER['REQUEST_URI']; + } // This section ensures that even on servers that require the URI to be in the query string (Nginx) a correct // URI is found, and also fixes the QUERY_STRING server var and $_GET array. - if (strncmp($uri, '?/', 2) === 0) + if (strpos($uri, '?/') === 0) { $uri = substr($uri, 2); } - $parts = preg_split('#\?#i', $uri, 2); + + $parts = explode('?', $uri, 2); $uri = $parts[0]; if (isset($parts[1])) { @@ -223,7 +227,7 @@ class CI_URI { return '/'; } - $uri = parse_url($uri, PHP_URL_PATH); + $uri = parse_url('pseudo://hostname/'.$uri, PHP_URL_PATH); // Do some final cleaning of the URI and return it return str_replace(array('//', '../'), '/', trim($uri, '/')); -- cgit v1.2.3-24-g4f1b From a8262ba2fe0e11302b8d81e1afba71d4f96cd6d7 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 14 Jun 2012 03:16:44 +0300 Subject: Fix an issue from d461934184d95b0cfb2feec93f27b621ef72a5c2 --- system/core/URI.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index 2e661ed4c..ef1a12650 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -189,11 +189,11 @@ class CI_URI { return ''; } - if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0) + if (strpos($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME']) === 0) { - $uri = substr($uri, strlen($_SERVER['SCRIPT_NAME'])); + $uri = substr($_SERVER['REQUEST_URI'], strlen($_SERVER['SCRIPT_NAME'])); } - elseif (strpos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0) + elseif (strpos($_SERVER['REQUEST_URI'], dirname($_SERVER['SCRIPT_NAME'])) === 0) { $uri = substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME']))); } -- cgit v1.2.3-24-g4f1b From fb859791182edd2f46479cd69ea4615daebed655 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 14 Jun 2012 03:32:19 +0300 Subject: And yet another missed line from the last one --- system/core/URI.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index ef1a12650..a997525ee 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -195,7 +195,7 @@ class CI_URI { } elseif (strpos($_SERVER['REQUEST_URI'], dirname($_SERVER['SCRIPT_NAME'])) === 0) { - $uri = substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME']))); + $uri = substr($_SERVER['REQUEST_URI'], strlen(dirname($_SERVER['SCRIPT_NAME']))); } else { -- cgit v1.2.3-24-g4f1b From 58ae971ba248cf3e32a139088c3833c9735028de Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 15 Jun 2012 23:44:48 +0300 Subject: Fix issue #167 --- system/core/URI.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index a997525ee..208d311a5 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -278,7 +278,7 @@ class CI_URI { { // preg_quote() in PHP 5.3 escapes -, so the str_replace() and addition of - to preg_quote() is to maintain backwards // compatibility as many are unaware of how characters in the permitted_uri_chars will be parsed as a regex pattern - if ( ! preg_match('|^['.str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-')).']+$|i', $str)) + if ( ! preg_match('|^['.str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-')).']+$|i', urldecode($str))) { show_error('The URI you submitted has disallowed characters.', 400); } -- cgit v1.2.3-24-g4f1b From 95d78cf4f78c0fb685a789c280d106ab242318ef Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 16 Jun 2012 19:54:33 +0300 Subject: Fix issue #999 --- system/core/URI.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index 208d311a5..6a8b1a5ac 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -302,9 +302,11 @@ class CI_URI { */ public function _remove_url_suffix() { - if ($this->config->item('url_suffix') !== '') + $suffix = (string) $this->config->item('url_suffix'); + + if ($suffix !== '' && ($offset = strrpos($this->uri_string, $suffix)) !== FALSE) { - $this->uri_string = preg_replace('|'.preg_quote($this->config->item('url_suffix')).'$|', '', $this->uri_string); + $this->uri_string = substr_replace($this->uri_string, '', $offset, strlen($suffix)); } } -- cgit v1.2.3-24-g4f1b