File tree Expand file tree Collapse file tree 3 files changed +67
-1
lines changed Expand file tree Collapse file tree 3 files changed +67
-1
lines changed Original file line number Diff line number Diff line change @@ -195,7 +195,24 @@ private function validatePhpPath(Config $config): void
195
195
if (empty ($ config ->getPhpPath ())) {
196
196
return ;
197
197
}
198
- if (!file_exists ($ config ->getPhpPath ())) {
198
+ $ foundPHP = false ;
199
+ $ pathToCheck = [$ config ->getPhpPath ()];
200
+ $ parts = explode (' ' , $ config ->getPhpPath ());
201
+ // if there are spaces in the php-path and they are not escaped
202
+ // it looks like an executable is used to find the PHP binary
203
+ // so at least check if the executable exists
204
+ if (count ($ parts ) > 1 && substr ($ parts [0 ], -1 ) !== '\\' ) {
205
+ $ pathToCheck [] = $ parts [0 ];
206
+ }
207
+
208
+ foreach ($ pathToCheck as $ path ) {
209
+ if (file_exists ($ path )) {
210
+ $ foundPHP = true ;
211
+ break ;
212
+ }
213
+ }
214
+
215
+ if (!$ foundPHP ) {
199
216
throw new RuntimeException ('The configured php-path is wrong: ' . $ config ->getPhpPath ());
200
217
}
201
218
}
Original file line number Diff line number Diff line change
1
+ {
2
+ "config" : {
3
+ "php-path" : " tests/files/bin/success foo"
4
+ },
5
+ "prepare-commit-msg" : {
6
+ "enabled" : true ,
7
+ "actions" : []
8
+ },
9
+ "commit-msg" : {
10
+ "enabled" : true ,
11
+ "actions" : []
12
+ },
13
+ "pre-commit" : {
14
+ "enabled" : true ,
15
+ "actions" : [
16
+ {
17
+ "action" : " phpunit --configuration=build/phpunit-hook.xml" ,
18
+ "options" : [],
19
+ "conditions" : [
20
+ {
21
+ "exec" : " \\ CaptainHook\\ App\\ Hook\\ Condition\\ AnyFileChanged" ,
22
+ "args" : [
23
+ [" foo.php" , " bar.php" ]
24
+ ]
25
+ }
26
+ ],
27
+ "config" : {
28
+ "allow-failure" : true
29
+ }
30
+ }
31
+ ]
32
+ },
33
+ "pre-push" : {
34
+ "enabled" : false ,
35
+ "actions" : []
36
+ }
37
+ }
Original file line number Diff line number Diff line change @@ -113,6 +113,18 @@ public function testCreateWithSettings(): void
113
113
$ this ->assertTrue ($ config ->getHookConfig ('pre-commit ' )->getActions ()[0 ]->isFailureAllowed ());
114
114
}
115
115
116
+ /**
117
+ * Tests Factory::create
118
+ *
119
+ * @throws \Exception
120
+ */
121
+ public function testCreateWithCrazyPHPPath (): void
122
+ {
123
+ $ config = Factory::create (realpath (__DIR__ . '/../../files/config/valid-with-strange-settings.json ' ));
124
+
125
+ $ this ->assertEquals ("tests/files/bin/success foo " , $ config ->getPhpPath ());
126
+ }
127
+
116
128
/**
117
129
* Tests Factory::create
118
130
*
You can’t perform that action at this time.
0 commit comments