From 6145df667059ca50b56107ba4128fa7ff892f8f5 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 3 Oct 2011 09:15:53 -0400 Subject: [PATCH 1/2] trim initial '/' from paths --- index.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/index.php b/index.php index 850208c9d1..49fd187100 100644 --- a/index.php +++ b/index.php @@ -49,21 +49,33 @@ $action = null; function getPath($req) { + $p = null; + if ((common_config('site', 'fancy') || !array_key_exists('PATH_INFO', $_SERVER)) && array_key_exists('p', $req) ) { - return $req['p']; + $p = $req['p']; } else if (array_key_exists('PATH_INFO', $_SERVER)) { $path = $_SERVER['PATH_INFO']; $script = $_SERVER['SCRIPT_NAME']; if (substr($path, 0, mb_strlen($script)) == $script) { - return substr($path, mb_strlen($script)); + $p = substr($path, mb_strlen($script)); } else { - return $path; + $p = $path; } } else { - return null; + $p = null; } + + // Trim all initial '/' + + if (!empty($p)) { + while ($p[0] == '/') { + $p = substr($p, 1); + } + } + + return $p; } /** From c9d635b67555e74f9d54ca5c1895a2fd186de653 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 3 Oct 2011 09:26:42 -0400 Subject: [PATCH 2/2] Fix hand-made trim in getPath() with ltrim (duh) --- index.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/index.php b/index.php index 49fd187100..1566399fa2 100644 --- a/index.php +++ b/index.php @@ -59,7 +59,7 @@ function getPath($req) $path = $_SERVER['PATH_INFO']; $script = $_SERVER['SCRIPT_NAME']; if (substr($path, 0, mb_strlen($script)) == $script) { - $p = substr($path, mb_strlen($script)); + $p = substr($path, mb_strlen($script) + 1); } else { $p = $path; } @@ -69,11 +69,7 @@ function getPath($req) // Trim all initial '/' - if (!empty($p)) { - while ($p[0] == '/') { - $p = substr($p, 1); - } - } + $p = ltrim($p, '/'); return $p; }