Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

$argv[0] can be empty #182

Merged
merged 4 commits into from
Dec 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/PhpEnvironment/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,13 @@ protected function detectBaseUrl()
// Backtrack up the SCRIPT_FILENAME to find the portion
// matching PHP_SELF.

$argv = $this->getServer()->get('argv', []);
if (isset($argv[0]) && strpos($filename, $argv[0]) === 0) {
$filename = substr($filename, strlen($argv[0]));
// Only for CLI requests argv[0] contains script filename
// @see https://www.php.net/manual/en/reserved.variables.server.php
if (PHP_SAPI === 'cli') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 This makes sense; only test argv if we're in a CLI request.

$argv = $this->getServer()->get('argv', []);
if (isset($argv[0]) && is_string($argv[0]) && $argv[0] !== '' && strpos($filename, $argv[0]) === 0) {
$filename = substr($filename, strlen($argv[0]));
}
}

$baseUrl = '/';
Expand Down