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 From f5f898f8f30968fb36413a14de2dc6a4599b79a6 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 23 Oct 2012 02:13:29 +0300 Subject: Fix issue #779 --- system/core/URI.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index 6a8b1a5ac..15e6a5599 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -165,11 +165,8 @@ class CI_URI { */ protected 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; + // Filter out control characters and trim slashes + $this->uri_string = trim(remove_invisible_characters($str, FALSE), '/'); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 4a7cc768a836a12c4839e482715b3859e0c16d7d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 24 Oct 2012 23:52:05 +0300 Subject: Fix #1811 --- system/core/URI.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index 15e6a5599..40eaaeb6b 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -433,9 +433,9 @@ class CI_URI { /** * Generate a key value pair from the URI string or Re-routed URI string * - * @param int the starting segment number - * @param array an array of default values - * @param string which array we should use + * @param int $n = 3 the starting segment number + * @param array $default = array() an array of default values + * @param string $which = 'segment' which array we should use * @return array */ protected function _uri_to_assoc($n = 3, $default = array(), $which = 'segment') @@ -445,9 +445,11 @@ class CI_URI { return $default; } - if (isset($this->keyval[$n])) + in_array($which, array('segment', 'rsegment'), TRUE) OR $which = 'segment'; + + if (isset($this->keyval[$which], $this->keyval[$which][$n])) { - return $this->keyval[$n]; + return $this->keyval[$which][$n]; } if ($which === 'segment') @@ -499,7 +501,7 @@ class CI_URI { } // Cache the array for reuse - $this->keyval[$n] = $retval; + $this->keyval[$which][$n] = $retval; return $retval; } -- cgit v1.2.3-24-g4f1b From 9093042c1f56bbdce2785ec5de0cd4180b4e6216 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 24 Oct 2012 23:53:12 +0300 Subject: Improve fix for #1811 --- system/core/URI.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index 40eaaeb6b..72f293c18 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -501,6 +501,7 @@ class CI_URI { } // Cache the array for reuse + isset($this->keyval[$which]) OR $this->keyval[$which] = array(); $this->keyval[$which][$n] = $retval; return $retval; } -- cgit v1.2.3-24-g4f1b From 4b322b18f3398e07275b74f615c2bf727a98a3cd Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 26 Oct 2012 15:37:28 +0300 Subject: Fix an improper usage of empty() in the URI class --- 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 72f293c18..13530bd63 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -219,7 +219,7 @@ class CI_URI { $_GET = array(); } - if ($uri === '/' OR empty($uri)) + if ($uri === '/' OR $uri === '') { return '/'; } -- cgit v1.2.3-24-g4f1b From 2b6b4300b36365bc060b1697e3f3c7088e6856e6 Mon Sep 17 00:00:00 2001 From: vkeranov Date: Sat, 27 Oct 2012 18:12:24 +0300 Subject: Update system/core/URI.php --- system/core/URI.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index 13530bd63..33f7d21fa 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -473,7 +473,7 @@ class CI_URI { $segments = array_slice($this->$segment_array(), ($n - 1)); $i = 0; $lastval = ''; - $retval = array(); + $retval = array(); foreach ($segments as $seg) { if ($i % 2) @@ -640,7 +640,6 @@ class CI_URI { return $this->uri_string; } - // -------------------------------------------------------------------- /** -- cgit v1.2.3-24-g4f1b From cca742750745de665d8071b38d6e368bf54cd985 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 28 Oct 2012 14:43:36 +0200 Subject: [ci skip] URI Library DocBlock improvements --- system/core/URI.php | 192 +++++++++++++++++++++++++++++----------------------- 1 file changed, 108 insertions(+), 84 deletions(-) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index 33f7d21fa..d67a35d4b 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -39,36 +39,37 @@ class CI_URI { /** - * List of cached uri segments + * List of cached URI segments * - * @var array + * @var array */ public $keyval = array(); /** - * Current uri string + * Current URI string * - * @var string + * @var string */ public $uri_string; /** - * List of uri segments + * List of URI segments * - * @var array + * @var array */ public $segments = array(); /** - * Re-indexed list of uri segments - * Starts at 1 instead of 0 + * Re-indexed list of URI segments * - * @var array + * Starts at 1 instead of 0. + * + * @var array */ public $rsegments = array(); /** - * Constructor + * Class constructor * * Simply globalizes the $RTR object. The front * loads the Router class early on so it's not available @@ -85,10 +86,9 @@ class CI_URI { // -------------------------------------------------------------------- /** - * Get the URI String - * - * Called by CI_Router + * Fetch URI String * + * @used-by CI_Router * @return void */ public function _fetch_uri_string() @@ -158,9 +158,9 @@ class CI_URI { // -------------------------------------------------------------------- /** - * Set the URI String + * Set URI String * - * @param string + * @param string $str * @return void */ protected function _set_uri_string($str) @@ -172,10 +172,9 @@ class CI_URI { // -------------------------------------------------------------------- /** - * Detects the URI + * Detects URI * - * This function will detect the URI automatically - * and fix the query string if necessary. + * Will detect the URI automatically and fix the query string if necessary. * * @return string */ @@ -233,10 +232,13 @@ class CI_URI { // -------------------------------------------------------------------- /** - * Is cli Request? + * Is CLI Request? * - * Duplicate of function from the Input class to test to see if a request was made from the command line + * Duplicate of method from the Input class to test to see if + * a request was made from the command line. * + * @see CI_Input::is_cli_request() + * @used-by CI_URI::_fetch_uri_string() * @return bool */ protected function _is_cli_request() @@ -247,7 +249,7 @@ class CI_URI { // -------------------------------------------------------------------- /** - * Parse cli arguments + * Parse CLI arguments * * Take each command line argument and assume it is a URI segment. * @@ -262,11 +264,12 @@ class CI_URI { // -------------------------------------------------------------------- /** - * Filter segments for malicious characters + * Filter URI * - * Called by CI_Router + * Filters segments for malicious characters. * - * @param string + * @used-by CI_Router + * @param string $str * @return string */ public function _filter_uri($str) @@ -291,10 +294,11 @@ class CI_URI { // -------------------------------------------------------------------- /** - * Remove the suffix from the URL if needed + * Remove URL suffix * - * Called by CI_Router + * Removes the suffix from the URL if needed. * + * @used-by CI_Router * @return void */ public function _remove_url_suffix() @@ -310,11 +314,12 @@ class CI_URI { // -------------------------------------------------------------------- /** - * Explode the URI Segments. The individual segments will - * be stored in the $this->segments array. + * Explode URI segments * - * Called by CI_Router + * The individual segments will be stored in the $this->segments array. * + * @see CI_URI::$segments + * @used-by CI_Router * @return void */ public function _explode_segments() @@ -336,13 +341,12 @@ 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 - * use functions like $this->uri->segment(n) since there is - * a 1:1 relationship between the segment array and the actual segments. - * - * Called by CI_Router + * Re-indexes the CI_URI::$segment array so that it starts at 1 rather + * than 0. Doing so makes it simpler to use methods like + * CI_URI::segment(n) since there is a 1:1 relationship between the + * segment array and the actual segments. * + * @used-by CI_Router * @return void */ public function _reindex_segments() @@ -356,13 +360,12 @@ class CI_URI { // -------------------------------------------------------------------- /** - * Fetch a URI Segment + * Fetch URI Segment * - * This function returns the URI segment based on the number provided. - * - * @param int - * @param mixed - * @return string + * @see CI_URI::$segments + * @param int $n Index + * @param mixed $no_result What to return if the segment index is not found + * @return mixed */ public function segment($n, $no_result = NULL) { @@ -372,15 +375,17 @@ class CI_URI { // -------------------------------------------------------------------- /** - * Fetch a URI "routed" Segment + * Fetch 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 - * same result as $this->segment() + * Returns the re-routed URI segment (assuming routing rules are used) + * based on the index provided. If there is no routing, will return + * the same result as CI_URI::segment(). * - * @param int - * @param mixed - * @return string + * @see CI_URI::$rsegments + * @see CI_URI::segment() + * @param int $n Index + * @param mixed $no_result What to return if the segment index is not found + * @return mixed */ public function rsegment($n, $no_result = NULL) { @@ -390,23 +395,23 @@ class CI_URI { // -------------------------------------------------------------------- /** - * Generate a key value pair from the URI string + * URI to assoc * - * This function generates and associative array of URI data starting - * at the supplied segment. For example, if this is your URI: + * Generates an associative array of URI data starting at the supplied + * segment index. For example, if this is your URI: * * example.com/user/search/name/joe/location/UK/gender/male * - * You can use this function to generate an array with this prototype: + * You can use this method to generate an array with this prototype: * - * array ( - * name => joe - * location => UK - * gender => male - * ) + * array ( + * name => joe + * location => UK + * gender => male + * ) * - * @param int the starting segment number - * @param array an array of default values + * @param int $n Index (default: 3) + * @param array $default Default values * @return array */ public function uri_to_assoc($n = 3, $default = array()) @@ -417,10 +422,14 @@ class CI_URI { // -------------------------------------------------------------------- /** - * Identical to above only it uses the re-routed segment array + * Routed URI to assoc + * + * Identical to CI_URI::uri_to_assoc(), only it uses the re-routed + * segment array. * - * @param int the starting segment number - * @param array an array of default values + * @see CI_URI::uri_to_assoc() + * @param int $n Index (default: 3) + * @param array $default Default values * @return array */ public function ruri_to_assoc($n = 3, $default = array()) @@ -431,11 +440,15 @@ class CI_URI { // -------------------------------------------------------------------- /** - * Generate a key value pair from the URI string or Re-routed URI string + * Internal URI-to-assoc * - * @param int $n = 3 the starting segment number - * @param array $default = array() an array of default values - * @param string $which = 'segment' which array we should use + * Generates a key/value pair from the URI string or re-routed URI string. + * + * @used-by CI_URI::uri_to_assoc() + * @used-by CI_URI::ruri_to_assoc() + * @param int $n Index (default: 3) + * @param array $default Default values + * @param string $which Array name ('segment' or 'rsegment') * @return array */ protected function _uri_to_assoc($n = 3, $default = array(), $which = 'segment') @@ -509,10 +522,12 @@ class CI_URI { // -------------------------------------------------------------------- /** - * Generate a URI string from an associative array + * Assoc to URI * - * @param array an associative array of key/values - * @return array + * Generates a URI string from an associative array. + * + * @param array $array Input array of key/value pairs + * @return string URI string */ public function assoc_to_uri($array) { @@ -529,10 +544,12 @@ class CI_URI { // -------------------------------------------------------------------- /** - * Fetch a URI Segment and add a trailing slash + * Slash segment + * + * Fetches an URI segment with a slash. * - * @param int - * @param string + * @param int $n Index + * @param string $where Where to add the slash ('trailing' or 'leading') * @return string */ public function slash_segment($n, $where = 'trailing') @@ -543,10 +560,12 @@ class CI_URI { // -------------------------------------------------------------------- /** - * Fetch a URI Segment and add a trailing slash + * Slash routed segment * - * @param int - * @param string + * Fetches an URI routed segment with a slash. + * + * @param int $n Index + * @param string $where Where to add the slash ('trailing' or 'leading') * @return string */ public function slash_rsegment($n, $where = 'trailing') @@ -557,11 +576,16 @@ class CI_URI { // -------------------------------------------------------------------- /** - * Fetch a URI Segment and add a trailing slash - helper function + * Internal Slash segment + * + * Fetches an URI Segment and adds a slash to it. * - * @param int - * @param string - * @param string + * @used-by CI_URI::slash_segment() + * @used-by CI_URI::slash_rsegment() + * + * @param int $n Index + * @param string $where Where to add the slash ('trailing' or 'leading') + * @param string $which Array name ('segment' or 'rsegment') * @return string */ protected function _slash_segment($n, $where = 'trailing', $which = 'segment') @@ -585,7 +609,7 @@ class CI_URI { /** * Segment Array * - * @return array + * @return array CI_URI::$segments */ public function segment_array() { @@ -597,7 +621,7 @@ class CI_URI { /** * Routed Segment Array * - * @return array + * @return array CI_URI::$rsegments */ public function rsegment_array() { @@ -631,9 +655,9 @@ class CI_URI { // -------------------------------------------------------------------- /** - * Fetch the entire URI string + * Fetch URI string * - * @return string + * @return string CI_URI::$uri_string */ public function uri_string() { @@ -643,7 +667,7 @@ class CI_URI { // -------------------------------------------------------------------- /** - * Fetch the entire Re-routed URI string + * Fetch Re-routed URI string * * @return string */ -- cgit v1.2.3-24-g4f1b From d4516e3562b1c412d7c3edea874eaa6e6922ad0e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 31 Oct 2012 14:44:38 +0200 Subject: CI_URI::_detect_uri() to accept absolute URIs (thanks to @sourcejedi, PR #1326) For HTTP/1.1 compliance, RFC2616 specifies that both relative and absolute URI formats must be accepted: - http://localhost/path/ (absolute) - /path/ (relative) --- system/core/URI.php | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index d67a35d4b..3d942eda7 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -185,37 +185,39 @@ class CI_URI { return ''; } - if (strpos($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME']) === 0) - { - $uri = substr($_SERVER['REQUEST_URI'], strlen($_SERVER['SCRIPT_NAME'])); - } - elseif (strpos($_SERVER['REQUEST_URI'], dirname($_SERVER['SCRIPT_NAME'])) === 0) + $uri = parse_url($_SERVER['REQUEST_URI']); + $query = isset($uri['query']) ? $uri['query'] : ''; + $uri = isset($uri['path']) ? $uri['path'] : ''; + + if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0) { - $uri = substr($_SERVER['REQUEST_URI'], strlen(dirname($_SERVER['SCRIPT_NAME']))); + $uri = (string) substr($uri, strlen($_SERVER['SCRIPT_NAME'])); } - else + elseif (strpos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0) { - $uri = $_SERVER['REQUEST_URI']; + $uri = (string) substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME']))); } - // 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 (strpos($uri, '?/') === 0) + + if ($uri === '' && strncmp($query, '/', 1) === 0) + { + $query = explode('?', $query, 2); + $uri = $query[0]; + $_SERVER['QUERY_STRING'] = isset($query[1]) ? $query[1] : ''; + } + else { - $uri = substr($uri, 2); + $_SERVER['QUERY_STRING'] = $query; } - $parts = explode('?', $uri, 2); - $uri = $parts[0]; - if (isset($parts[1])) + if ($_SERVER['QUERY_STRING'] === '') { - $_SERVER['QUERY_STRING'] = $parts[1]; - parse_str($_SERVER['QUERY_STRING'], $_GET); + $_GET = array(); } else { - $_SERVER['QUERY_STRING'] = ''; - $_GET = array(); + parse_str($_SERVER['QUERY_STRING'], $_GET); } if ($uri === '/' OR $uri === '') @@ -223,8 +225,6 @@ class CI_URI { return '/'; } - $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 f2b19fee7876708c7a7bb5cba6b7df682a9d2a53 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 31 Oct 2012 16:16:24 +0200 Subject: Multiple improvements to the URI class (thanks to @sourcejedi, PR #1326 for most of the ideas) - Renamed _detect_uri() and _parse_cli_args() to _parse_request_uri() and _parse_argv() respectively. - Added _parse_query_string() which allows us to detect the URI path from QUERY_STRING much like it is done in _parse_request_uri(). (the above changes also allow for a simpler logic in the case where the *uri_protocol* setting is not set to 'AUTO') - Updated application/config/config.php with a better list of the *uri_protocol* options. - Added _reset_query_string() to aid in re-processing from the QUERY_STRING (utilized in _parse_request_uri() and _parse_query_string()). --- system/core/URI.php | 103 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 75 insertions(+), 28 deletions(-) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index 3d942eda7..6692d07a6 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -98,12 +98,12 @@ class CI_URI { // Is the request coming from the command line? if ($this->_is_cli_request()) { - $this->_set_uri_string($this->_parse_cli_args()); + $this->_set_uri_string($this->_parse_argv()); return; } // Let's try the REQUEST_URI first, this will work in most situations - if ($uri = $this->_detect_uri()) + if (($uri = $this->_parse_request_uri()) !== '') { $this->_set_uri_string($uri); return; @@ -111,18 +111,17 @@ 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) + $uri = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); + if (trim($uri, '/') !== '' && $uri !== '/'.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'); - if (trim($path, '/') !== '') + if (($uri = $this->_parse_query_string()) !== '') { - $this->_set_uri_string($path); + $this->_set_uri_string($uri); return; } @@ -140,19 +139,19 @@ class CI_URI { $uri = strtoupper($this->config->item('uri_protocol')); - if ($uri === 'REQUEST_URI') + if ($uri === 'CLI') { - $this->_set_uri_string($this->_detect_uri()); + $this->_set_uri_string($this->_parse_argv()); return; } - elseif ($uri === 'CLI') + elseif (method_exists($this, ($method = '_parse_'.strtolower($uri)))) { - $this->_set_uri_string($this->_parse_cli_args()); + $this->_set_uri_string($this->$method()); return; } - $path = isset($_SERVER[$uri]) ? $_SERVER[$uri] : @getenv($uri); - $this->_set_uri_string($path); + $uri = isset($_SERVER[$uri]) ? $_SERVER[$uri] : @getenv($uri); + $this->_set_uri_string($uri); } // -------------------------------------------------------------------- @@ -172,13 +171,15 @@ class CI_URI { // -------------------------------------------------------------------- /** - * Detects URI + * Parse REQUEST_URI * - * Will detect the URI automatically and fix the query string if necessary. + * Will parse REQUEST_URI and automatically detect the URI from it, + * while fixing the query string if necessary. * + * @used-by CI_URI::_fetch_uri_string() * @return string */ - protected function _detect_uri() + protected function _parse_request_uri() { if ( ! isset($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME'])) { @@ -197,10 +198,10 @@ class CI_URI { { $uri = (string) substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME']))); } + // 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 ($uri === '' && strncmp($query, '/', 1) === 0) + if (trim($uri, '/') === '' && strncmp($query, '/', 1) === 0) { $query = explode('?', $query, 2); $uri = $query[0]; @@ -211,14 +212,7 @@ class CI_URI { $_SERVER['QUERY_STRING'] = $query; } - if ($_SERVER['QUERY_STRING'] === '') - { - $_GET = array(); - } - else - { - parse_str($_SERVER['QUERY_STRING'], $_GET); - } + $this->_reset_query_string(); if ($uri === '/' OR $uri === '') { @@ -231,6 +225,59 @@ class CI_URI { // -------------------------------------------------------------------- + /** + * Parse QUERY_STRING + * + * Will parse QUERY_STRING and automatically detect the URI from it. + * + * @used-by CI_URI::_fetch_uri_string() + * @return string + */ + protected function _parse_query_string() + { + $uri = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); + + if (trim($uri, '/') === '') + { + return ''; + } + elseif (strncmp($uri, '/', 1) === 0) + { + $uri = explode('?', $uri, 2); + $_SERVER['QUERY_STRING'] = isset($uri[1]) ? $uri[1] : ''; + $uri = $uri[0]; + } + $this->_reset_query_string(); + + return str_replace(array('//', '../'), '/', trim($uri, '/')); + } + + // -------------------------------------------------------------------- + + /** + * Reset QUERY_STRING + * + * Re-processes QUERY_STRING to and fetches the real GET values from it. + * Useful for cases where we got the URI path from it's query string. + * + * @used-by CI_URI::_parse_request_uri() + * @used-by CI_URI::_parse_query_string() + * @return void + */ + protected function _reset_query_string() + { + if ($_SERVER['QUERY_STRING'] === '') + { + $_GET = array(); + } + else + { + parse_str($_SERVER['QUERY_STRING']); + } + } + + // -------------------------------------------------------------------- + /** * Is CLI Request? * @@ -255,10 +302,10 @@ class CI_URI { * * @return string */ - protected function _parse_cli_args() + protected function _parse_argv() { $args = array_slice($_SERVER['argv'], 1); - return $args ? '/'.implode('/', $args) : ''; + return $args ? implode('/', $args) : ''; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 704f3f5223637dd6008106b1d04a68668458590e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 31 Oct 2012 16:50:13 +0200 Subject: Fix an erroneous variable name --- 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 6692d07a6..407a6ce88 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -114,7 +114,7 @@ class CI_URI { $uri = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); if (trim($uri, '/') !== '' && $uri !== '/'.SELF) { - $this->_set_uri_string($path); + $this->_set_uri_string($uri); return; } -- cgit v1.2.3-24-g4f1b From 9dd2dbb8b9a3edecddcb3907b65a402fd1ae71b4 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 31 Oct 2012 17:54:56 +0200 Subject: Fix issues #388 & #705 (thanks to @sourcejedi, PR #1326 for pointing inconsistencies with RFC2616 --- system/core/URI.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index 407a6ce88..4a8d33e88 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -188,7 +188,7 @@ class CI_URI { $uri = parse_url($_SERVER['REQUEST_URI']); $query = isset($uri['query']) ? $uri['query'] : ''; - $uri = isset($uri['path']) ? $uri['path'] : ''; + $uri = isset($uri['path']) ? rawurldecode($uri['path']) : ''; if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0) { @@ -204,7 +204,7 @@ class CI_URI { if (trim($uri, '/') === '' && strncmp($query, '/', 1) === 0) { $query = explode('?', $query, 2); - $uri = $query[0]; + $uri = rawurldecode($query[0]); $_SERVER['QUERY_STRING'] = isset($query[1]) ? $query[1] : ''; } else @@ -245,8 +245,9 @@ class CI_URI { { $uri = explode('?', $uri, 2); $_SERVER['QUERY_STRING'] = isset($uri[1]) ? $uri[1] : ''; - $uri = $uri[0]; + $uri = rawurldecode($uri[0]); } + $this->_reset_query_string(); return str_replace(array('//', '../'), '/', trim($uri, '/')); @@ -325,7 +326,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', urldecode($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); } -- cgit v1.2.3-24-g4f1b From ea6688b3b9a7a208d1c44439c4f01801fd3b8c65 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 31 Oct 2012 21:52:11 +0200 Subject: Fix issue in resetting QUERY_STRING, GET vars introduced in f2b19fee7876708c7a7bb5cba6b7df682a9d2a53 --- system/core/URI.php | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index 4a8d33e88..3b7718fff 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -212,7 +212,7 @@ class CI_URI { $_SERVER['QUERY_STRING'] = $query; } - $this->_reset_query_string(); + parse_str($_SERVER['QUERY_STRING'], $_GET); if ($uri === '/' OR $uri === '') { @@ -248,37 +248,13 @@ class CI_URI { $uri = rawurldecode($uri[0]); } - $this->_reset_query_string(); + parse_str($_SERVER['QUERY_STRING'], $_GET); return str_replace(array('//', '../'), '/', trim($uri, '/')); } // -------------------------------------------------------------------- - /** - * Reset QUERY_STRING - * - * Re-processes QUERY_STRING to and fetches the real GET values from it. - * Useful for cases where we got the URI path from it's query string. - * - * @used-by CI_URI::_parse_request_uri() - * @used-by CI_URI::_parse_query_string() - * @return void - */ - protected function _reset_query_string() - { - if ($_SERVER['QUERY_STRING'] === '') - { - $_GET = array(); - } - else - { - parse_str($_SERVER['QUERY_STRING']); - } - } - - // -------------------------------------------------------------------- - /** * Is CLI Request? * -- cgit v1.2.3-24-g4f1b From 3b72eb58e61581b7e92012a322be48e216491d7c Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Nov 2012 00:45:26 +0200 Subject: Changed URI auto-detection to try PATH_INFO first (thanks to @sourcejedi, PR #1326) Up until PHP 5.2.4 (which is our new lowest requirement), there was a bug related to PATH_INFO which made REQUEST_URI a more reliable choice. This is now no longer the case, see https://bugs.php.net/bug.php?id=31892 for more details. Also removed ORIG_PATH_INFO from the suggested alternatives for uri_protocol in application/config/config.php as it will not exist in most of PHP's recent versions and is pointless when you can use PATH_INFO anyway. --- system/core/URI.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index 3b7718fff..309c77630 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -102,23 +102,21 @@ class CI_URI { return; } - // Let's try the REQUEST_URI first, this will work in most situations - if (($uri = $this->_parse_request_uri()) !== '') + // Is there a PATH_INFO variable? This should be the easiest solution. + if (isset($_SERVER['PATH_INFO'])) { - $this->_set_uri_string($uri); + $this->_set_uri_string($_SERVER['PATH_INFO']); return; } - // Is there a PATH_INFO variable? - // Note: some servers seem to have trouble with getenv() so we'll test it two ways - $uri = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); - if (trim($uri, '/') !== '' && $uri !== '/'.SELF) + // Let's try REQUEST_URI then, this will work in most situations + if (($uri = $this->_parse_request_uri()) !== '') { $this->_set_uri_string($uri); return; } - // No PATH_INFO?... What about QUERY_STRING? + // No REQUEST_URI either?... What about QUERY_STRING? if (($uri = $this->_parse_query_string()) !== '') { $this->_set_uri_string($uri); -- cgit v1.2.3-24-g4f1b From c5536aac5752054f7f76e448d58b86407d8f574e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Nov 2012 17:33:58 +0200 Subject: Manually apply PR #1594 (fixing phpdoc page-level generation/warnings) Also partially fixes issue #1295, fixes inconsistencies in some page-level docblocks and adds include checks in language files. --- system/core/URI.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index 309c77630..2f6cade34 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -1,4 +1,4 @@ - Date: Thu, 1 Nov 2012 21:21:20 +0200 Subject: Fix issue #122 --- system/core/URI.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index 2f6cade34..e2cac8d89 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -696,7 +696,14 @@ class CI_URI { */ public function ruri_string() { - return implode('/', $this->rsegment_array()); + global $RTR; + + if (($dir = $RTR->fetch_directory()) === '/') + { + $dir = ''; + } + + return $dir.implode('/', $this->rsegment_array()); } } -- cgit v1.2.3-24-g4f1b From c3751f843e9e4f646f3da2617df25cae6660f3af Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 2 Nov 2012 16:50:00 +0200 Subject: Fix #1956 --- 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 e2cac8d89..91740254c 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -301,7 +301,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', $str)) { show_error('The URI you submitted has disallowed characters.', 400); } -- cgit v1.2.3-24-g4f1b From af3bd3e57fa7b381a670d3b96d9bb49d142739c8 Mon Sep 17 00:00:00 2001 From: chernjie Date: Thu, 6 Dec 2012 12:06:50 +0800 Subject: Bug fix for relative directory removal This fixes two bugs: - for segments that ends with ".." e.g. /user/username../details, this should not be replaced - current solution only replace double slashes, this solutions removes the infinite number of recurring slashes --- system/core/URI.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index 91740254c..3f8775d4e 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -219,7 +219,26 @@ class CI_URI { } // Do some final cleaning of the URI and return it - return str_replace(array('//', '../'), '/', trim($uri, '/')); + return $this->_remove_relative_directory_str($uri); + } + + // -------------------------------------------------------------------- + + /** + * Remove relative directory (../) and multi slashes (///) + * @param string $url + * @return string + */ + private function _remove_relative_directory_str($url) + { + $uris = array(); + $tok = strtok($url, '/'); + while ($tok !== false) + { + ($tok != '..' && ! empty($tok) || $tok === '0') && $uris[] = $tok; + $tok = strtok('/'); + } + return implode('/', $uris); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 0bf9cfa127516a5561155d70a8edfa3c6b0ec57b Mon Sep 17 00:00:00 2001 From: CJ Date: Thu, 6 Dec 2012 17:15:49 +0800 Subject: Updated formatting and styleguide, thanks narfbg; --- system/core/URI.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'system/core/URI.php') diff --git a/system/core/URI.php b/system/core/URI.php index 3f8775d4e..07add5a4d 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -219,23 +219,29 @@ class CI_URI { } // Do some final cleaning of the URI and return it - return $this->_remove_relative_directory_str($uri); + return $this->_remove_relative_directory($uri); } // -------------------------------------------------------------------- /** * Remove relative directory (../) and multi slashes (///) - * @param string $url - * @return string + * + * Do some final cleaning of the URI and return it, currently only used in self::_parse_request_uri() + * + * @param string $url + * @return string */ - private function _remove_relative_directory_str($url) + protected function _remove_relative_directory($uri) { $uris = array(); - $tok = strtok($url, '/'); - while ($tok !== false) + $tok = strtok($uri, '/'); + while ($tok !== FALSE) { - ($tok != '..' && ! empty($tok) || $tok === '0') && $uris[] = $tok; + if (( ! empty($tok) OR $tok === '0') && $tok !== '..') + { + $uris[] = $tok; + } $tok = strtok('/'); } return implode('/', $uris); -- cgit v1.2.3-24-g4f1b From b2280ced6f7214f3df40754152208ac3f3f02bce Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 6 Dec 2012 16:19:22 +0200 Subject: Another use of CI_URI::_remove_relative_directory() --- 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 07add5a4d..900472b61 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -274,7 +274,7 @@ class CI_URI { parse_str($_SERVER['QUERY_STRING'], $_GET); - return str_replace(array('//', '../'), '/', trim($uri, '/')); + return $this->_remove_relative_directory($uri); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b