File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44
55use Closure ;
66use Kirby \Exception \Exception ;
7- use Kirby \Filesystem \F ;
87use Kirby \Http \Response ;
98use Kirby \Toolkit \I18n ;
109use Throwable ;
@@ -38,6 +37,25 @@ trait AppErrors
3837 */
3938 protected Whoops $ whoops ;
4039
40+ /**
41+ * Replaces absolute file paths with placeholders such as
42+ * {kirby_folder}, {site_folder} or {index_folder} to avoid
43+ * exposing too many details about the filesystem and keeping
44+ * error responses short and readable in debug mode.
45+ *
46+ * @since 5.3.0
47+ */
48+ protected function disguiseFilePath (string $ file ): string
49+ {
50+ $ disguise = [
51+ $ this ->root ('kirby ' ) => '{kirby} ' ,
52+ $ this ->root ('site ' ) => '{site} ' ,
53+ $ this ->root ('index ' ) => '{index} '
54+ ];
55+
56+ return str_replace (array_keys ($ disguise ), array_values ($ disguise ), $ file );
57+ }
58+
4159 /**
4260 * Registers the PHP error handler for CLI usage
4361 */
@@ -150,10 +168,7 @@ protected function handleJsonErrors(): void
150168 'code ' => $ code ,
151169 'message ' => $ exception ->getMessage (),
152170 'details ' => $ details ,
153- 'file ' => F::relativepath (
154- $ exception ->getFile (),
155- $ this ->environment ()->get ('DOCUMENT_ROOT ' , '' )
156- ),
171+ 'file ' => $ this ->disguiseFilePath ($ exception ->getFile ()),
157172 'line ' => $ exception ->getLine (),
158173 ], $ httpCode );
159174 } else {
Original file line number Diff line number Diff line change @@ -344,7 +344,7 @@ public function testHandleJsonErrors(): void
344344 'details ' => [
345345 'Some error message '
346346 ],
347- 'file ' => basename ( __FILE__ ) ,
347+ 'file ' => ' {kirby}/tests/Cms/App/AppErrorsTest.php ' ,
348348 'line ' => $ exception ->getLine ()
349349 ]), $ this ->_getBufferedContent ($ handlers [0 ]));
350350 $ this ->assertInstanceOf ('Whoops\Handler\CallbackHandler ' , $ handlers [1 ]);
You can’t perform that action at this time.
0 commit comments