Skip to content

Commit e2539dc

Browse files
committed
Fix: diagnose command replace backslashes with forwardslashes, and filter the valet home path.
- Fix for the nginx config check command, where it errors out because it couldn't find the file due to the path after the `-c` option couldn't be the shortened username via the `valetBinPath()`. Changed it back to use `__DIR__` . And added an escaped double quotes (`\"`) around it. - Fix for the nginx config check command, where it also errorred out not finding the file due to the replacing of all backslashes in the command. This meant that with the new escaped double quotes it changed the backslash to forward slash. So instead of `-c \"C:/Users/...` it was changed to `-c /"C:/Users/...` and the system interpreted it as ``"C:/C:/Users/...` Fixed by changing the replace function to use a regex that only replaces single backslashes and disregards the escaped quotes. - Fix for the composer global diagnose command where it would error out when there's a space in the user directory name. Fixed by making sure it also uses the shortname via the `pathFilter()`.
1 parent 962d7f0 commit e2539dc

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

cli/Valet/Diagnose.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ public function __construct(CommandLine $cli, Filesystem $files) {
2828
'systeminfo',
2929
'valet --version',
3030
'cat ~/.config/valet/config.json',
31-
valetBinPath() . 'nginx\nginx.exe -v 2>&1',
32-
valetBinPath() . 'nginx\nginx.exe -c ' . valetBinPath() . 'nginx\conf\nginx.conf -t -p ' . valetBinPath() . 'nginx 2>&1',
33-
'foreach ($file in get-ChildItem -Path "' . valetBinPath() . 'nginx\conf\nginx.conf", "' . valetBinPath() . 'nginx\valet\valet.conf", "' . VALET_HOME_PATH . '/Nginx/*.conf"){echo $file.fullname --------------------`n; Get-Content -Path $file; echo `n;}',
31+
valetBinPath() . 'nginx/nginx.exe -v 2>&1',
32+
valetBinPath() . 'nginx/nginx.exe -c \"' . __DIR__ . '/../../bin/nginx/conf/nginx.conf\" -t -p ' . valetBinPath() . 'nginx 2>&1',
33+
'foreach ($file in get-ChildItem -Path "' . valetBinPath() . 'nginx/conf/nginx.conf", "' . valetBinPath() . 'nginx/valet/valet.conf", "' . VALET_HOME_PATH . '/Nginx/*.conf"){echo $file.fullname --------------------`n; Get-Content -Path $file; echo `n;}',
3434
valetBinPath() . 'ngrok.exe version',
3535
'php -v',
3636
'cmd /C "where /f php"',
@@ -97,7 +97,11 @@ protected function beforeRun() {
9797
if ($this->print) {
9898
return;
9999
}
100-
$this->commands = str_replace("\\", "/", $this->commands);
100+
101+
// Replace only single backslashes (\) within paths to forward slashes (/), ie. does not replace the backslashes
102+
// before a double quote. So the double quote is still escaped.
103+
// e.g. \"\..\path\" --> \"/../path\"
104+
$this->commands = preg_replace('/\\\(?![\\"])/', "/", $this->commands);
101105

102106
$this->progressBar = progressbar(count($this->commands), "Diagnosing", "Valet");
103107
}

cli/includes/helpers.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
/*
2020
* Define the ~/.config/valet path as a constant.
2121
*/
22-
define('VALET_HOME_PATH', $_SERVER['HOME'] . '/.config/valet');
22+
define('VALET_HOME_PATH', pathFilter($_SERVER['HOME'] . '/.config/valet'));
2323
define('VALET_SERVER_PATH', str_replace('\\', '/', realpath(__DIR__ . '/../../server.php')));
2424
define('VALET_STATIC_PREFIX', '41c270e4-5535-4daa-b23e-c269744c2f45');
2525
/**
@@ -404,7 +404,7 @@ function pathFilter($path) {
404404

405405
$path = implode(DIRECTORY_SEPARATOR, $path);
406406

407-
return $path;
407+
return str_replace('\\', '/', $path);
408408
}
409409

410410
/**

0 commit comments

Comments
 (0)