From 9acea5b424bf682d2012fcf7f2595c6075e16a7e Mon Sep 17 00:00:00 2001 From: Jack Cherng Date: Wed, 5 Jun 2019 14:14:20 +0800 Subject: [PATCH] Fix chrome binary path for Windows OS The binary path under Windows are usually like the following one. C:\Program Files (x86)\Google\Chrome\Application\chrome.exe The problem is that there is a space in the path and it causes the glued shell command to be split accidentally. So I guess it would be good to always use a quoted path if possible. Signed-off-by: Jack Cherng --- src/BrowserFactory.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/BrowserFactory.php b/src/BrowserFactory.php index b5f06e5e..9a8eedb9 100644 --- a/src/BrowserFactory.php +++ b/src/BrowserFactory.php @@ -31,6 +31,15 @@ public function __construct(string $chromeBinaries = null) } } + // special path handling for Windows, try to use a shell-safe (quoted) path + if ( + PHP_OS === 'WINNT' + // has no quote in the path yet + && strcspn($chromeBinaries, '\'"') >= strlen($chromeBinaries) + ) { + $chromeBinaries = '"' . $chromeBinaries . '"'; + } + $this->chromeBinaries = $chromeBinaries; }