Skip to content

Commit 98899e1

Browse files
committed
More false processing / fall back
1 parent fcffd6c commit 98899e1

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

src/Util/U.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,13 @@ public static function get_rest_parent($uri=false) {
168168
*/
169169
public static function parse_rest_path($uri=false, $SERVER_SCRIPT_NAME=false /* unit test only */) {
170170
if ( ! $SERVER_SCRIPT_NAME ) $SERVER_SCRIPT_NAME = $_SERVER["SCRIPT_NAME"]; // /py4e/koseu.php
171-
if ( ! $uri ) $uri = $_SERVER['REQUEST_URI']; // /py4e/lessons/intro/happy
171+
if ( ! $uri ) {
172+
// Handle missing REQUEST_URI (e.g., CLI mode or certain web server configs)
173+
if ( !isset($_SERVER['REQUEST_URI']) ) {
174+
return false;
175+
}
176+
$uri = $_SERVER['REQUEST_URI']; // /py4e/lessons/intro/happy
177+
}
172178
// Remove Query string...
173179
$pos = strpos($uri, '?');
174180
if ( $pos !== false ) $uri = substr($uri,0,$pos);

tests/Util/UTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ public function testParseController() {
8989
// Running from the wrong directory
9090
$this->assertEquals(U::parse_rest_path('/a/b/c','/x/koseu.php'), false);
9191

92+
// Test that rest_path also returns false when parse_rest_path returns false
93+
$CFG->wwwroot = "http://www.example.com:8888/tsugi";
94+
$this->assertEquals(U::rest_path('/a/b/c','/x/koseu.php'), false);
95+
9296
// Object version...
9397
$CFG->wwwroot = "http://www.example.com:8888/tsugi";
9498
$path = U::rest_path('/py4e/lessons/intro?x=2','/py4e/koseu.php');

0 commit comments

Comments
 (0)