File tree Expand file tree Collapse file tree 1 file changed +17
-9
lines changed Expand file tree Collapse file tree 1 file changed +17
-9
lines changed Original file line number Diff line number Diff line change 4646 $ idleTimeout = true ;
4747 }
4848
49- if (checkForFilePath ($ output )) {
50- $ output = "CLI output suppressed, filepath detected in output. " ;
51- }
52-
5349 $ exitCode = $ process ->getExitCode ();
5450
5551 if ($ process ->isSuccessful () || $ idleTimeout ) {
5652 http_response_code (202 );
5753 } else {
5854 http_response_code (500 );
5955 }
60- echo $ output ;
56+
57+ // Suppress file paths from output
58+ echo suppressFilePaths ($ output );
6159 } else {
6260 http_response_code (403 );
6361 echo "Given command not found valid in Magento CLI Command list. " ;
@@ -115,11 +113,21 @@ function trimAfterWhitespace($string)
115113}
116114
117115/**
118- * Detects file path in string.
116+ * Suppress file paths in string.
119117 * @param string $string
120- * @return boolean
118+ * @return string
121119 */
122- function checkForFilePath ( $ string )
120+ function suppressFilePaths ( string $ string ): string
123121{
124- return preg_match ('/\/[\S]+\// ' , $ string );
122+ // Match file paths on both *nix and Windows system
123+ $ filePathPattern = '~(?:[A-Za-z]:[ \\\/]| \\\\|\/)\S+~ ' ;
124+ $ replacement = '[suppressed_path] ' ;
125+
126+ preg_match_all ($ filePathPattern , $ string , $ matches );
127+ if (!empty ($ matches )) {
128+ foreach ($ matches [0 ] as $ match ) {
129+ $ string = str_replace ($ match , $ replacement , $ string );
130+ }
131+ }
132+ return $ string ;
125133}
You can’t perform that action at this time.
0 commit comments